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
what parameter should we put in place to have this order back?
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].
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.