Solr:搜索包含连字符的字段

时间:2015-10-02 12:29:39

标签: solr solrj spring-data-solr

我使用spring-data-solr(version = 1.4.0.RELEASE)来搜索包含连字符的字段,但结果为零。我的一个索引字段包含值为"沃尔玛"当我搜索" wal"它给出了正确的结果,但是在搜索" wal - "我得到零结果。我之前尝试添加一个转义反斜杠字符 - 但它没有帮助。有人可以告诉我这里可能出现什么问题吗?

以下是我的schema.xml的快照。

            <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
  <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.
    -->
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="lang/stopwords_en.txt"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
    <filter class="solr.PorterStemFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="lang/stopwords_en.txt"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
    <filter class="solr.PorterStemFilterFactory"/>
  </analyzer>
</fieldType>

1 个答案:

答案 0 :(得分:4)

将preserveOriginal =“1”参数添加到索引和查询分析器上的WordDelimiterFilterFactory中。目前generateWordParts将为您带来沃尔玛的Wal和Mart。 preserveOriginal将添加原始术语沃尔玛进行搜索。