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

前端 未结 2 511
無奈伤痛
無奈伤痛 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:49

    So what I ended up doing is using lucence payloads and solr 6.6 new DelimitedPayloadTokenFilter feature.

    First I created a terms field with the following configuration:

    {
     "add-field-type": {
       "name": "terms",
       "stored": "true",
       "class": "solr.TextField",
       "positionIncrementGap": "100",
       "indexAnalyzer": {
         "tokenizer": {
           "class": "solr.KeywordTokenizerFactory"
         },
         "filters": [
           {
             "class": "solr.LowerCaseFilterFactory"
           },
           {
             "class": "solr.DelimitedPayloadTokenFilterFactory",
             "encoder": "float",
             "delimiter": "|"
           }
         ]
       },
       "queryAnalyzer": {
         "tokenizer": {
           "class": "solr.KeywordTokenizerFactory"
         },
         "filters": [
           {
             "class": "solr.LowerCaseFilterFactory"
           },
           {
             "class": "solr.SynonymGraphFilterFactory",
             "ignoreCase": "true",
             "expand": "false",
             "tokenizerFactory": "solr.KeywordTokenizerFactory",
             "synonyms": "synonyms.txt"
           }
         ]
       }
     },
    
     "add-field" : {
       "name":"terms",
       "type":"terms",
       "stored": "true",
       "multiValued": "true"
     }
    }
    

    I indexed my documents likes so:

    [
      {
        "id" : "1",
        "terms" : [
          "some term|10.0",
          "another term|60.0"
        ]
      }
    ,
       {
        "id" : "2",
        "terms" : [
          "some term|11.0",
          "another term|21.0"
        ]
      }
    ]
    

    I used solr's functional query support to query for a match on terms and grab the attached boost payload and apply it to the relevancy score:

    /solr/payloads/select?indent=on&wt=json&q={!payload_score%20f=ai_terms_wtih_synm_3%20v=$payload_term%20func=max}&fl=id,score&payload_term=some+term
    

提交回复
热议问题