【问题标题】:Search for two-letter words in Lucene在 Lucene 中搜索两个字母的单词
【发布时间】:2013-08-15 23:30:54
【问题描述】:

我正在尝试查找包含首字母缩略词“IT”的文档。

我尝试使用 StandardAnalyzer、SimpleAnalyzer 和 KeywordAnalyzer 进行搜索 - 结果相同(没有任何命中)。

据我所知,“它”不是默认停用词的一部分?

可以使用通配符搜索找到文档,所以我知道它们在索引中。

非常感谢任何帮助!干杯!

【问题讨论】:

    标签: lucene lucene.net


    【解决方案1】:

    默认停用词集确实包含单词“it”。在StopAnalyzer中定义,它是:

    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"
     );
    

    SimpleAnalyzerKeywordAnalyzer 均未使用停用词,因此由于某些其他问题(可能是对它们如何标记化的误解,或者索引和查询时间分析器之间存在分歧),这些不起作用。

    【讨论】:

    • 奇怪,我没有在 Lucene 3.0 的停用词中看到“它”。大概只是错过了。谢谢!
    【解决方案2】:

    我尝试在没有任何停用词的情况下重新索引...

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

    ...之后,只要我使用相同类型的分析器(没有任何停用词)进行搜索,我就可以搜索“it”:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多