Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOLR search filter by relevancy score

So each SOLR search result has their own relevancy score:

https://wiki.apache.org/solr/SolrRelevancyFAQ

"How can I see the relevancy scores for search results

Request that the pseudo-field named "score" be returned by adding it to the fl (field list) parameter. The "score" will then appear along with the stored fields in returned documents. q=Justice League&fl=*,score"

My question is...is it possible to filter SOLR results by this relevancy score?

Eg. perform a query in the nature of the following

Search for keyword "LOL" and only fetch documents whose relevancy score > 50

If it's possible how would you go about specifying this query syntactically?

like image 970
pillarOfLight Avatar asked Aug 28 '14 16:08

pillarOfLight


People also ask

What is relevance in Solr?

Relevance is the degree to which a query response satisfies a user who is searching for information. The relevance of a query response depends on the context in which the query was performed. A single search application may be used in different contexts by users with different needs and expectations.

How do you use exact match in Solr?

Phrase match: A simple way by which we can achieve exact matching in Solr is by using the default string type. It is exact phrase matching. the string is a useful type for facet where we search the index by using the text pulled from the index itself.

What does FQ mean in Solr?

The fq (Filter Query) Parameter The fq parameter defines a query that can be used to restrict the superset of documents that can be returned, without influencing score. It can be very useful for speeding up complex queries, since the queries specified with fq are cached independently of the main query.

What are wildcard search parameters Solr?

The wildcard search: tes* would match test, testing, and tester. You can also use wildcard characters in the middle of a term. For example: te*t would match test and text. *est would match pest and test.


2 Answers

I spent hours trying to filter out values with a relevance score of 0. I couldn't find any straight forward way to do this. I ended up accomplishing this with a workaround that assigns the query function to a local param. I call this local param in both the query ("q=") and the filter query ("fq=").

Example

Let's say you have a query like:

q={!func}sum(*your arguments*)

First, make the function component its own parameter:

q={!func}$localParam
&localParam={!func}sum(*your arguments*)

Now to only return results with scores between 1 and 10 simply add a filter query on that localParam:

q={!func}$localParam
&localParam={!func}sum(*your arguments*)
&fq={!frange l=1 u=10 inclusive=true}$localParam
like image 55
helloparth Avatar answered Oct 01 '22 11:10

helloparth


You can specify a maximum number of results to return. The results will appear in descending order by score, so you could stop processing at a specific point in the result set.

solr/search/select?q=LOL&&start=0&rows=10&fl=*%2Cscore

See the following article for a discussion about setting a minimum score: Is it possible to set a Solr Score threshold 'reasonably', independent of results returned? (i.e. Is Solr Scoring standardized in any way)

like image 29
terrywb Avatar answered Oct 01 '22 12:10

terrywb