For example, this way:
1. Implement a filter factory:
[code]
package com.mycomp.solr.analysis;
import org.apache.lucene.analysis.TokenStream;
import org.apache.solr.analysis.BaseTokenFilterFactory;
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.util.plugin.ResourceLoaderAware;
public class MyNewFilterFactory extends BaseTokenFilterFactory implements
ResourceLoaderAware {
public void inform(ResourceLoader loader) {
//no need
}
public MyNewIndexingFilter create(TokenStream input) {
return new MyNewIndexingFilter(input);
}
}
[/code]
2. Implement the filter itself:
[code]
package com.mycomp.solr.analysis;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import java.io.IOException;
...
/**
* Allows filtering tokens in my own super-cool way
*/
public class MyNewIndexingFilter extends TokenFilter {
public MyNewIndexingFilter(TokenStream input) {
super(input);
this.termAtt = addAttribute(CharTermAttribute.class);
this.posAtt = addAttribute(PositionIncrementAttribute.class);
}
@Override
public boolean incrementToken() throws IOException {
// handle the token filtering
if( save != null ) {
// clearAttributes(); // not currently necessary
restoreState(save);
save = null;
return true;
}
if (input.incrementToken()) {
// do your magic
return true;
}
return false;
}
}
[/code]
3. compile a jar with both classes and place it into the lib directory
visible to solr. Modify your schema, start solr and check the analysis page
in solr admin
Dmitry
On Fri, Feb 24, 2012 at 12:07 PM, dsy99 <[email protected]> wrote:
> Dear all,
> I want to include my own filter for analysis of tokens while indexing the
> documents in SOLR.
>
> Is there any explicit interface for programming compatible filters in SOLR?
>
> Please let me know the steps to be followed to use my own filters in
> Schema.xml file. I mean, If I create a java class for a filter as per my
> requirement then how I can use/integrate it in SOLR schema.xml file for
> indexing the documents.
>
> Thanks in advance.
>
> With regds:
> Divakar Yadav
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/What-Interface-to-use-for-programming-compatible-filters-in-SOLR-tp3772171p3772171.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>