0

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

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

"text:happiness"

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

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

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

4

1 回答 1

0

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

<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>

这给了我所需的行为。

于 2011-04-14T01:15:12.357 回答