You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ravis <ra...@gmail.com> on 2008/10/13 23:54:46 UTC
Custom Sorting Based on Input Value
Hi,
I have a sorting requirement where I need to bubble up documents exactly
matching of particular value passed in sort criteria.
For example: Hypothetically, Say I am sorting on field A. I want all values
matching value '5' on top and then regular sorting for other values. So I
would like to do something like: sort by: fieldA(5).
Any recommendation how I can achieve this using Lucene.
thanks,
Ravi
--
View this message in context: http://www.nabble.com/Custom-Sorting-Based-on-Input-Value-tp19963673p19963673.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Custom Sorting Based on Input Value
Posted by Chris Hostetter <ho...@fucit.org>.
: 3> maybe you could provide a custom sorter by using
: SortComparator, although you should look at the warnings
: in the API.
:
: Now I'll wait for Hoss to say "Isn't that what XXX provides" <G>...
I can't think of anything that would solve this problem direclty, mianly
because i can't think of any practical use for a requirement like this,
but one way it should be possible to solve this while avoiding the
pitfalls people run into when subclassing SortComparator would be to avoid
SortComparator (and it's use of FieldCache.DEFAULT.getCustom) and
implement SortComparatorSource directly ... you don't need to *cache* a
big array of true/false booleans for when the value does or doesnt' equal
your magic input, can use FieldCache.DEFAULT.getInt or
FieldCache.DEFAULT.getStrings, or whatever you need directly (just like a
normal sort) but let the compare and sortValue short circut if the value
isn't what it needs to be.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Custom Sorting Based on Input Value
Posted by Erick Erickson <er...@gmail.com>.
I don' know how tight your result must be, but here's a couple
of ideas....
1> you could boost your target by a huge amount, although forming
your query might be "interesting". If you somehow worked the clause
fieldA:5^10000 say. I suspect that some of your results wouldn't be on
top, but it might be "close enough".
2> you could do something with FieldSortedHitQueue
3> maybe you could provide a custom sorter by using
SortComparator, although you should look at the warnings
in the API.
Now I'll wait for Hoss to say "Isn't that what XXX provides" <G>...
Best
Erick
On Mon, Oct 13, 2008 at 5:54 PM, Ravis <ra...@gmail.com> wrote:
>
> Hi,
>
> I have a sorting requirement where I need to bubble up documents exactly
> matching of particular value passed in sort criteria.
>
> For example: Hypothetically, Say I am sorting on field A. I want all values
> matching value '5' on top and then regular sorting for other values. So I
> would like to do something like: sort by: fieldA(5).
>
> Any recommendation how I can achieve this using Lucene.
>
> thanks,
> Ravi
> --
> View this message in context:
> http://www.nabble.com/Custom-Sorting-Based-on-Input-Value-tp19963673p19963673.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>