【问题标题】:Is it possible to apply a solr document int field value as boost value if a specific field is matched?如果匹配特定字段,是否可以应用 solr 文档 int 字段值作为提升值?
【发布时间】:2018-03-05 16:45:12
【问题描述】:
Ex. 

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

如果 'field_1' 匹配,则通过相应的 'boost' 字段进行提升。

【问题讨论】:

    标签: solr


    【解决方案1】:

    提升什么?文件?具体领域?你可以做任何一个。 无论如何,这样做的方法是用户功能查询: https://lucene.apache.org/solr/guide/6_6/function-queries.html#FunctionQueries-AvailableFunctions

    例如,如果您想提升文档(并假设如果值不匹配,则分数为 0),那么您可以执行以下操作:

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

    _val_ 只是 Solr 函数查询的一个钩子,query 如果 q1 匹配则返回 true,field 是一个简单的函数,它只返回它自己的字段值,if 允许我们将两者结合在一起。

    【讨论】:

    • 太棒了!我想这就是我一直在寻找的。你知道函数式查询的性能如何吗?
    • 我没有测量它,但是通过一些手动测试,我没有看到对包含几百万个文档的索引有重大影响(如果有的话)。而且它真的取决于功能。
    【解决方案2】:

    所以我最终做的是使用 lucence payloads 和 solr 6.6 新的 DelimitedPayloadTokenFilter 功能。

    首先我使用以下配置创建了一个术语字段:

    {
     "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"
     }
    }
    

    我索引我的文档喜欢这样:

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

    我使用 solr 的功能查询支持来查询匹配项并获取附加的 boost 有效负载并将其应用于相关性分数:

    /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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多