【问题标题】:Solr queryparser for lucene indices?用于 lucene 索引的 Solr 查询解析器?
【发布时间】:2011-04-13 20:48:29
【问题描述】:

我创建了一个存储文本消息的索引(使用 Lucene 2.9)。 (文档还包含其他一些未编入索引的元数据,只是存储)我使用 StandardAnalyzer 来解析这些消息。我正在尝试使用 Solr 对此索引运行一些测试(我用我的索引替换了示例应用程序索引),以查看我从各种查询中得到什么样的结果。

当我尝试以下查询时,我得到了 0 个结果

"text:happiness"

但是,将其更改为 "text:happiness*" 会给我一些结果。它们都包含"happiness,", "happiness." 等术语。所以我认为这是索引创建期间的标记化问题,但是,当我使用 Luke(一个 lucene 索引调试工具)运行相同的查询(text:happiness) 时,我得到了确切的我从 Solr 获得的幸福*结果相同,这让我相信问题不在于索引,而在于我指定 Solr 查询的方式。我查看了 solrconfig.xml,注意到它有以下行(注释),我尝试取消注释它,然后修改我的查询以在原始查询之外使用“defType=lucene”,但得到了相同的结果。

  <queryParser name="lucene" class="org.apache.solr.search.LuceneQParserPlugin"/>

我对 Solr 的经验很少,因此非常感谢任何帮助 :)

【问题讨论】:

  • 我可以通过更改我的 solrconfig.xml 来解决这个问题
  • 您可以发布您的解决方案作为答案并接受它。
  • 我发布了我的解决方案,我需要等待 2 天才能接受。

标签: lucene solr luke


【解决方案1】:

我查询的字段在 solr schema.xml 中被定义为“文本”类型(不是 solrconfig.xml,因为我在之前的评论中错误地提到了)。这是来自 schema.xml 的相关 sn-p

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!-- Case insensitive stop word removal.
          add enablePositionIncrements=true in both the index and query
          analyzers to leave a 'gap' for more accurate phrase queries.
        -->

我将其替换为以下内容,

<fieldType name = "text" class="solr.TextField">
      <analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
    </fieldType>

这给了我所需的行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多