Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I limit by score before sorting in a solr query

Tags:

solr

scoring

I am searching "product documents". In other words, my solr documents are product records. I want to get say the top 50 matching products for a query. Then I want to be able to sort the top 50 scoring documents by name or price. I'm not seeing much on how to do this, since sorting by score, then by name or price won't really help, since scores are floats.

I wouldn't mind if I could do something like map the scores to ranges (like a score of 8.0-8.99 would go in the 8 bucket score), then sort by range, then by names, but since there is basically no normalization to scoring, this would still make things a bit harder.

Tl;dr How do I exclude low scoring documents from the solr result set before sorting?

like image 345
Zak Avatar asked Dec 07 '10 22:12

Zak


People also ask

What is the difference between Q and FQ in solr?

Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter. The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).

What is FQ in solr query?

The fq (Filter Query) ParameterThe 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 is WT in solr?

Solr supports a variety of Response Writers to ensure that query responses can be parsed by the appropriate language or application. The wt parameter selects the Response Writer to be used. The table below lists the most common settings for the wt parameter.


2 Answers

You can use frange to achieve this, as long as you don't want to sort on score (in which case I guess you could just do the filtering on the client side).

Your query would be something along the lines of:

q={!frange l=5}query($qq)&qq=[awesome product]&sort=price asc

Set the l argument in the q-frange-parameter to the lower bound you want to filter score on, and replace the qq parameter with your user query.

like image 73
Karl Johansson Avatar answered Sep 28 '22 08:09

Karl Johansson


As observed by Karl Johansson, you could do the filtering on the client side: load the first 50 rows of the response (sorted by score desc) and then manipulate them in JS for example.

The jQuery DataTables plugin works fantastically for that kind of thing: sorting, sorting on multiple columns, dynamic filtering, etc. -- and with only 50 rows it would be very fast too, so that users can "play" with the sorting and filtering until they find what they want.

like image 26
Bambax Avatar answered Sep 28 '22 08:09

Bambax