简体   繁体   中英

Boost SOLR relevancy by position of match in multivalued field

I'm using SOLR 6.2.1, and has the core with multivalued field:

<field name="tag_ids" type="ints" required="false"  indexed="true"  stored="true"/>

It allows to search documents by tag id, with query eg tag_ids:12 . I have tags into this field, sorted by tag relevancy for the document. I want to sort by document tag relevancy.

Example - search query tag_ids:12 , documents:

[
{
   id: 1,
   tag_ids:[1298,43,12,89]
},
{
   id: 2,
   tag_ids:[12,574,1,4356]
},
{
   id: 3,
   tag_ids:[77,12,65]
}
]

Wanting to see documents with order 2,3,1 .

Question : Is it possible to order by position of match in multi-valued field in Apache SOLR? May be some hacks or plugins?

What you need to do is add the weight information for each tag at index time, and your query would work as is.

To index the weight with each tag, you have several ways:

  1. Try with payloads, here is a complete example for an older version of Solr, here is another. You probably would need to modify this samples as Solr apis have changed since then.
  2. Use the know hack of adding N times each tag, in your examples that would look like:

    [ { id: 1, tag_ids:[1298,1298,1298,1298,43,43,43,12,12,89] }, { id: 2, tag_ids:[12,12,12,12,574,574,1,1,4356] }, { id: 3, tag_ids:[77,77,77,77,12,12,12,65,65] }]

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