Is it possible to apply a solr document int field value as boost value if a specific field is matched?

前端 未结 2 540
無奈伤痛
無奈伤痛 2021-01-28 17:06
Ex. 

\"docs\": [
{
\"id\": \"f37914\",
\"index_id\": \"some_index\",
\"field_1\": [
   {
      \"Some value\",
      \"boost\": 20.
   }
 ]
},
]

If \'

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 17:41

    Boost what? the document? the specific field? you can do any of them. Anyway the way to do it is to user Function Queries: https://lucene.apache.org/solr/guide/6_6/function-queries.html#FunctionQueries-AvailableFunctions

    For example if you want to boost the document (and assuming if the value doesn't match then the score is 0) then you can do something like that:

    q:_val_:"if(query($q1), field(boost), 0)"&q1=field_1:"Some Value"
    

    _val_ is just a hook into Solr function query, query returns true if q1 matches, field is a simple function that just return the value of the field it self and if allows us to join the two together.

提交回复
热议问题