Search for two-letter words in Lucene

你离开我真会死。 提交于 2019-12-08 13:37:43

问题


I'm trying to find documents containing the acronym "IT".

I've tried searching using the StandardAnalyzer, SimpleAnalyzer and KeywordAnalyzer - same result (no hits whatsoever).

As far as I can see, "it" isn't part of the default stop words?

I can find the documents using a wildcard search, so I know they're in the index.

Any help is greatly appreciated! Cheers!


回答1:


The default stopword set does include the word "it". It is defined in StopAnalyzer, and it is:

final List<String> stopWords = Arrays.asList(
   "a", "an", "and", "are", "as", "at", "be", "but", "by",
   "for", "if", "in", "into", "is", "it",
   "no", "not", "of", "on", "or", "such",
   "that", "the", "their", "then", "there", "these",
   "they", "this", "to", "was", "will", "with"
 );

Neither SimpleAnalyzer nor KeywordAnalyzer use stopwords, so these didn't work due to some other issue, possibly a misunderstanding of how they tokenize, or a disagreement between index and query time analyzers.




回答2:


I tried re-indexing without any stop words...

new IndexWriter(directory,
                new StandardAnalyzer(Version.LUCENE_30, new HashSet<string>()), // No stop words
                true,
                IndexWriter.MaxFieldLength.UNLIMITED);

...and after that I was able to search for "it" as long as I used the same type of analyzer (without any stop words) for searching:

new StandardAnalyzer(Version.LUCENE_30, new HashSet<string>()


来源:https://stackoverflow.com/questions/18255015/search-for-two-letter-words-in-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!