您好,登錄后才能下訂單哦!
如何將tfidf映射到[1,3] 區間內
(1)建立映射x→arctanx,此為一一映射,把全體實數R映射到開區間(-π/2,π/2)
(2)開區間(-π/2,π/2)到開區間(0,1)只需要一個線性映射就可以,設為f(x)=ax+b,則有f(-π/2)=1且f(π/2)=3,解得a=2/π,b=2
綜合一下,映射x→2(arctanx)/π+2,即把全體實數映射到(1,3)
所以表達式可以寫成
"script_score" : {
"script" : "return atan(_score.doubleValue())*2/3.14159+2"
}
為了只使用函數值 設置 "boost_mode": "replace",
所以整個請求如下
curl -XGET 'http://localhost:9200/*/*/_search?pretty&explain' -d '{
"size" : 1,
"query" : {
"function_score" : {
"query" : {
"bool" : {
"should" : [ {
"match" : {
"_all" : {
"query" : "關鍵字",
"type" : "boolean",
"operator" : "AND",
"boost": 10
}
}
}, {
"match" : {
"company_name" : {
"query" : "關鍵字",
"type" : "boolean",
"operator" : "AND",
"boost": 10
}
}
} ],
"minimum_should_match" : "1"
}
},
"functions" : [
{
"script_score" : {
"script" : "return atan(_score.doubleValue())*2/3.14159+2"
}
},{
"filter" : {
"match" : {
"company_name" : {
"query" : "關鍵字",
"type" : "boolean",
"operator" : "AND"
}
}
},
"weight" : 2
}
],
"score_mode" : "sum",
"boost_mode": "replace"
}
},
"aggregations" : {
"agg" : {
"terms" : {
"field" : "member_id",
"size" : 0,
"order" : {
"top_hit" : "desc"
}
},
"aggregations" : {
"top_hit" : {
"max" : {
"script" : {
"inline" : "_score"
}
}
}
}
}
}
}'
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。