You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Stephane Bailliez <sb...@gmail.com> on 2012/03/29 21:09:07 UTC

Post Sorting hook before the doc slicing.

I'm currently looking to see what would be a decent way to implement a
scrolling window in the result set when looking for an item.

Basically, I need to find item X in the result set and return say N items
before and N items after.

< ----- N items -- Item X --- N items ---->

So I was thinking a post filter could do the work, where I'm basically
looking for the id of the document, select it + the N documents after.
This is easy to do, however in the end it cannot work since this doc
selection need to happen post sorting while the post filtering is before
the sorting.

So I might be wrong, but it looks like the only way would be to create a
custom SolrIndexSearcher which will find the offset and create the related
docslice. That slicing part doesn't seem to be well factored that I can
see, so it seems to imply copy/pasting a significant chunk off the code. Am
I looking at the wrong place ?

-- stephane

Re: Post Sorting hook before the doc slicing.

Posted by Chris Hostetter <ho...@fucit.org>.
: Basically, I need to find item X in the result set and return say N items
: before and N items after.
: 
: < ----- N items -- Item X --- N items ---->
	...
: So I might be wrong, but it looks like the only way would be to create a
: custom SolrIndexSearcher which will find the offset and create the related
: docslice. That slicing part doesn't seem to be well factored that I can
: see, so it seems to imply copy/pasting a significant chunk off the code. Am
: I looking at the wrong place ?

trying to do this as a hook into the SolrIndexSearcher would definitley be 
complicated ... laregley because of how matches are collected.

the most straight forward way i can think of to get the data you want is 
to consider what you are sorting on, and use that as a range filter, ie...

1) do your search, and filter on id:X
2) look at the values X has in the fields you are sorting on
3) search again, this time filter on those fields, asking for the first N 
docs with values greater then whatever id:X has
4) search again, this time reverse your sort, and reverse your filters 
(docs with values less hten whatever id:X has) and get the first N docs.


...even if your sort is "score" you can use the frange parser to filter 
(not usually recommended for score, but possible)



-Hoss