Prakhar Nigam
Prakhar Nigam

Reputation: 658

How to use Synonymap in lucene 6.2.0

I'm using apache Lucene 6.2.0 and I'm trying to implement a custom analyzer for searching . This is My Analyzer Class

        public static class  myAnalyzer extends Analyzer
{
    @Override
    protected TokenStreamComponents createComponents(String reader) {
        final StandardTokenizer tok = new StandardTokenizer();

        TokenStream result = new StandardFilter((TokenStream) tok);
        result = new LowerCaseFilter(result);
        return new TokenStreamComponents(tok, result); 

}
}

now when i am searching the index it is giving me illegal state exception like this.

Exception in thread "main" java.lang.IllegalStateException: TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.
at org.apache.lucene.analysis.Tokenizer$1.read(Tokenizer.java:109)

i tried using result.close(); but it didnt solved the problem..
so what am i doing wrong ? am I using two instances of the same analyzer.

Any code example would be highly helpful.

Upvotes: 2

Views: 99

Answers (1)

femtoRgon
femtoRgon

Reputation: 33351

createComponents does not take a Reader argument anymore, so that method is not being called. The method that will actually be called is the one that actually overrides the one in Analyzer, which, in your implementation, is just a stub that returns null.

So remove createComponents(string, Reader), and put your code in createComponents(string) (removing the call to Tokenizer.setReader, of course).

Upvotes: 2

Related Questions