确切的词没有提高Solr

时间:2015-06-09 12:14:15

标签: solr lucene edismax dismax solr-boost

作为给定链接中的参考

https://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_make_exact-case_matches_score_higher

我试了一个例子。我的schema.xml配置如下所示。

     <field name="product_name" type="text_wslc" indexed="true" stored="true" required="true" multiValued="false"/>
        <field name="nameString" type="string_ci" indexed="true" stored="false" required="true" />
                <copyField source="product_name" dest="nameString"/>

<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
                <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
                <fieldType name="text_wslc" class="solr.TextField" positionIncrementGap="100">
                        <analyzer type="index">
                                  <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
                        <filter class="solr.WordDelimiterFilterFactory"
                             generateWordParts="1"
                             generateNumberParts="1"
                             catenateWords="1"
                             catenateNumbers="1"
                             catenateAll="1"
                             preserveOriginal="1"
                             />
                <filter class="solr.LowerCaseFilterFactory"/>
                <filter class="solr.SnowballPorterFilterFactory" language="English" />
                <filter class="solr.PorterStemFilterFactory"/>
                <filter class="solr.KStemFilterFactory"/>
                <filter class="solr.EnglishMinimalStemFilterFactory"/>
                        </analyzer>
                        <analyzer type="query">
                                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.WordDelimiterFilterFactory"
                             generateWordParts="1"
                             generateNumberParts="1"
                             catenateWords="1"
                             catenateNumbers="1"
                             catenateAll="1"
                             preserveOriginal="1"
                             />
                                <filter class="solr.LowerCaseFilterFactory"/>
                <filter class="solr.SnowballPorterFilterFactory" language="English" />
                <filter class="solr.PorterStemFilterFactory"/>
                <filter class="solr.KStemFilterFactory"/>
                <filter class="solr.EnglishMinimalStemFilterFactory"/>
                        </analyzer>
                </fieldType>

<fieldType name="string_ci" class="solr.TextField" tMissingLast="true" omitNorms="true">
            <analyzer type="query">
            <tokenizer class="solr.KeywordTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
        </fieldType>

确切的单词搜索可以正常使用。

但是使用精确匹配提升的模糊搜索不会产生预期的结果。 这是我的查询

/select?q=(laptop bag)&defType=dismax&qf=nameString^22+product_name^0.1

任何帮助?

1 个答案:

答案 0 :(得分:1)

您需要以这种方式创建新的字段类型...

<fieldType name="string_ci" class="solr.TextField"
    sortMissingLast="true" omitNorms="true">
    <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>           
        <filter class="solr.LowerCaseFilterFactory" />
    </analyzer>
</fieldType>

现在像这样创建字段nameSrting

<field name="nameSrting" type="string_ci" indexed="true" stored="true"/>

并将product_name的内容复制到nameSrting,如下所示:

<copyField source="product_name" dest="nameSrting"/>

现在你需要运行一个查询,指明你想要使用双引号来获得精确的短语:

http://localhost:8983/solr/Dummy2/select?q=“笔记本电脑+包”&amp; wt = json&amp; defType = dismax&amp; qf = nameSrting ^ 222 + product_name ^ 0.1