4
votes

I am creating a lucene search application, I used multiple instances of indexWriter with different analyzers and respective indexSearcher, but the search results returned are empty even though I know I have indexed the particular word I'm searching for.

Here is my SearchEngine class constructor

this.indexers = new ArrayList<StandardIndexer>();
    this.indexers.add(new StandardIndexer(new StandardAnalyzer()));
    this.indexers.add(new StandardIndexer(new EnglishStemAnalyzer()));
    this.indexers.add(new StandardIndexer(new KeywordAnalyzer()));
    this.indexers.add(new StandardIndexer(new EnglishSynonymAnalyzer()));
    this.indexers.add(new StandardIndexer(new EnglishSynonymStemAnalyzer()));
    this.indexers.add(new StandardIndexer(new EnglishSynonymKeywordAnalyzer()));
    this.searchers = new ArrayList<StandardSearcher>();
    for (StandardIndexer indexer : this.indexers) {
        this.searchers.add(new StandardSearcher(indexer));
    }

StandardIndexer and StandardSearcher are my implementations of indexer and searcher, as we can see instance of indexer is used in creation of indexSearcher, hence directory and type of analyzer used is also shared between pairs of indexer and searcher

1

1 Answers

0
votes

Your question is about a known bug in unknown code.

So I write in general:

  • You have to use "nearly" the same analyzer for indexing and searching. So in the end the token (=word after stemming) in index must match the token in query.
  • You must be sure that a commit is finished before your can search an indexed document.
  • Be aware that the standard query parser split words at whitespace. You can not search for tokens with whitespace without extra work (escaping the whitespace, search with phrase ..)
  • You can use luke to view your index directory https://github.com/DmitryKey/luke