Re: Query elevation / boosting or something else to guarantee document position

2012-05-31 Thread Michael Kuhlmann

Hi Wenca,

I'm a bit late. but maybe you're still interested.

There's no such functionality in standard Solr. With sorting, this is 
not possible, because sort functions only rank each single document, 
they know nothing about the position of the others. And query elevation 
is similar, you'll raise the score of independent documents.


To achive this, you'll need an own QueryComponent. This isn't too 
complicated. You can't change the SolrIndexSearcher easily, this does 
the search job. But you can subclass 
org.apache.solr.handler.component.QueryComponent and overwrite 
process(). Alas the single main line - searcher.search() - is buried 
deeply in the huge monster method process(), and you first have to check 
for shards, grouping and twentythousand other parameters until you've 
arrived the code line you may want to expand.


Before calling search(), set the GET_DOCSET flag in your QueryCommand 
object, then execute the search. To check whether there's a document of 
the particular manufacturer in the result list, you can either
a) fetch the appropriate field value from the default field cache for 
every single result document until you found one; or
b) call getDocSet() on the SolrIndexSearcher with the manufacturer query 
as the parameter, and perform and and() operation on the resulting 
DocSet with the DocSet of your main query. (That's why you set the flag 
before.) You can then check which document that matches both the 
manufacturer and the main query fits best.


If you found a matching document, but it's behind pos. 5 in the 
resulting DocList, the you simoply have to re-order your list.


If there's no such document within the DocList (which is limited by your 
rows parameter), but there are some in the joined DocSet from strategy 
b), then you can simply choose one of them and ignore the fact that this 
is probably not the best matching one. Or you have to patch Solr and 
modify getDocListNC() in solrIndexSearcher (or one of the Collector 
classes), which is much more complicated.


Good luck!
-Kuli

Am 29.05.2012 14:26, schrieb Wenca:

Hi all,

I have an index with thousands of products with various fields
(manufacturer, price, popularity, type, color, ...) and I want to
guarantee at least one product by a particular manufacturer to be within
the first 5 results.

The search is done mainly by using filter params and results are ordered
by function e.g.: "product(price, popularity) asc" or by "discount desc"

And I need to guarantee that if there is any product matching the given
filters made by a concrete manufacturer, then it will be on the 5th
position at worst, even if the position by the order function is worse.

It seems to me that the Query elevation component is not the right thing
for me. I don't know the query in advance (or the set of filter
criteria) and I don't know concrete product that will be the best for
the criteria within the order.

And also I don't think that I can construct a function with such
requirements to use it directly for ordering the results.

Of course I can make a second query in case there is no desired product
on the first page of results and put it there, but it requires
additional request to solr and complicates results processing and
further pagination.

Can anybody suggest any solution?

Thanks
Wenca




Query elevation / boosting or something else to guarantee document position

2012-05-29 Thread Wenca

Hi all,

I have an index with thousands of products with various fields 
(manufacturer, price, popularity, type, color, ...) and I want to 
guarantee at least one product by a particular manufacturer to be within 
the first 5 results.


The search is done mainly by using filter params and results are ordered 
by function e.g.: "product(price, popularity) asc" or by  "discount desc"


And I need to guarantee that if there is any product matching the given 
filters made by a concrete manufacturer, then it will be on the 5th 
position at worst, even if the position by the order function is worse.


It seems to me that the Query elevation component is not the right thing 
for me. I don't know the query in advance (or the set of filter 
criteria) and I don't know concrete product that will be the best for 
the criteria within the order.


And also I don't think that I can construct a function with such 
requirements to use it directly for ordering the results.


Of course I can make a second query in case there is no desired product 
on the first page of results and put it there, but it requires 
additional request to solr and complicates results processing and 
further pagination.


Can anybody suggest any solution?

Thanks
Wenca