简体   繁体   中英

relevance by keyword solr

How can we sort the results of a query according to the position of the keyword?

I start the search only on the field Label

when I have

  1. solr search query titi
  2. titi test tilte
  3. toto titi tata

what parameter should we put in place to have this order back?

  1. titi test tilte
  2. toto titi tata
  3. solr search query titi

I use Drupal for connect and send query to solr.

If your domain is very contained and you know for example the size of the label you expect you can obtain something close to what you want with copy fields and the dismax query parser. Specifically you could build N "copyfields" in this way :

 <field name="label" type="text_general" indexed="true" stored="true"/> <field name="label_3" type="text_first_3" indexed="true" stored="true"/> <field name="label_5" type="text_first_5" indexed="true" stored="true"/> ... <fieldType name="text_first_3" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LimitTokenPositionFilterFactory" maxTokenPosition="3" consumeAllTokens="false" /> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> </analyzer> </fieldType> <fieldType name="text_first_5" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LimitTokenPositionFilterFactory" maxTokenPosition="5" consumeAllTokens="false" /> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> </analyzer> </fieldType> ... <copyField source="label" dest="label_3"/> <copyField source="label" dest="label_5"/> 

This works thanks to the limit token position filter[1]. Then you can specify a different boost with the edismax :

qf="label_3^5 label_5^2 label"

The problem is also discussed here [2].

An alternative approach is mentioned here[3].

[1] https://lucene.apache.org/solr/guide/6_6/filter-descriptions.html#FilterDescriptions-LimitTokenPositionFilter

[2] https://issues.apache.org/jira/browse/SOLR-3925

[3] Solr - How to boost score for early matches?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM