Boost result by specified search term on top

2020-07-29 17:04发布

问题:

I'm using apache solr 3.1 with drupal

How can boost result on top which is specified in search field?

Example in search field, if user enters continuing, solr shows the document which have Continuity on top and the one with continuing below, i want to show the one with continuing above than the Continuity

http://localhost:8983/solr/select/?q=continuing&qf=title&fl=title%20score&bq=title:continuing^10.0

回答1:

It seems you have stemmer in the filter chains, due to which continuing and Continuity and mapped to the same root and would be treated equal.

you want want to check for the stemmer you are using and want to get one depending upon your needs. The default porter stemmer is very agressive, and you may want an less agressive options.

Solr does not currently boost the exact match higher than the other terms which generated the same root.
One option would be to have two fields in your schema.
Stemmed (title_stemmed) and a Non Stemmed version (title - without the stemming filter)

example -

schema.xml -

<!-- Without Porter Stemmer -->
<fieldType name="text_non_stemmed" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

<!-- With Porter Stemmer -->
<fieldType name="text" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
</fieldType>

<field name="title" type="text" indexed="true" stored="true" termVectors="false" omitNorms="false"/>    
<field name="title_non_stemmed" type="text_non_stemmed" indexed="true" stored="true" termVectors="false" omitNorms="false"/>

<copyField source="title" dest="title_non_stemmed"/>

you can weight the fields -

solrconfig.xml - modify the default request handler

<requestHandler name="search" class="solr.SearchHandler" default="true">
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <str name="defType">dismax</str>
   <str name="qf">
      title_non_stemmed^1 title^0.8
   </str>
   <str name="q.alt">*:*</str>
   <str name="rows">10</str>
   <str name="fl">*,score</str>
 </lst>
</requestHandler>

so that the exact match produces more score than the non exact matches and appears higher.

URL -

http://localhost:8983/solr/select/?q=continuing


标签: solr