koblas
koblas

Reputation: 27078

Recompose into function query

Using Solr 4.0 I have the following query:

(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)

Where HIGHQUALITY and SVC1..SVC5 are not the real names of the values of the "source" field. We can't quite assume that they're alpha ordered, or could ever be...

What I'm looking for is a function that returns a boost based on the value of the source indexed field, rather than doing a bunch of queries for the field. In solr-hybrid-pseudocode:

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

Upvotes: 1

Views: 278

Answers (1)

Hoss
Hoss

Reputation: 26

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))

Upvotes: 1

Related Questions