1

使用 Solr 4.0 我有以下查询:

(family_name:(Brown) OR maiden_name:(Brown)^0.5) AND (
    source:HIGHQUALITY^3000 OR source:SVC1^2000 OR 
    source:SVC2 OR source:SVC3 OR 
    source:SVC4 OR source:SVC5)

其中 HIGHQUALITY 和 SVC1..SVC5 不是“源”字段值的真实名称。我们不能完全假设它们是 alpha 有序的,或者可能永远是......

我正在寻找的是一个基于源索引字段的值返回提升的函数,而不是对该字段进行一堆查询。在 solr-hybrid-pseudocode 中:

{!boost 
    switch (source) {
    case "HIGHQUALITY": return 3
    case "SVC1": return 2
    default: return 1
    }
}
4

1 回答 1

1

If your boost weightings are generally static (ie: don't change for every request) then the most straight forward way to do something like this is with external file field...

lucene.apache.org/solr/api/org/apache/solr/schema/ExternalFileField.html

It's common use case is to contain a mapping of "id=value" pairs for each doc, but there is no requirement that the lookup field be the id / uniqueKey. You could (in your specific case) have a simple file listing the 5 mappings for each of The known values in your "source" field, as well as a default mapping, and then that numerical value can be used in a function.

If you really need to specify a switch using arbitrary values at query time, then there are some new functions available in trunk that should make this possible using nested "if" functions (but I haven't personally tested this)...

wiki.apache.org/solr/FunctionQuery#if

wiki.apache.org/solr/FunctionQuery#termfreq

if(termfreq(source,'HIGHQLTY'),3,if(termfreq(source,'SVC1'),2,1))
于 2012-05-10T15:25:58.693 回答