我创建了一个存储文本消息的索引(使用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的经验很少,所以非常感谢任何帮助:)
答案 0 :(得分:0)
我正在查询的字段在solr schema.xml中定义为“text”类型(不是我之前的评论中错误提到的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>
这给了我所需的行为。