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 Johannes Siegert <jo...@marktjagd.de> on 2015/03/12 10:16:34 UTC

sort by given order

Hi,

i want to sort my documents by a given order. The order is defined by a 
list of ids.

My current solution is:

list of ids: 15, 5, 1, 10, 3

query: q=*:*&fq=(id:((15) OR (5) OR (1) OR (10) OR 
(3)))&sort=query($idqsort) desc,id asc&idqsort=id:((15^5) OR (5^4) OR 
(1^3) OR (10^2) OR (3^1))&start=0&rows=5

Do you know an other solution to sort by a list of ids?

Thanks!

Johannes

Re: sort by given order

Posted by Erick Erickson <er...@gmail.com>.
Not unless you can somehow codify that sort order at index time, but
I'm assuming the sort order changes dynamically.

You can also sort by function, but that's not really useful.

Or, if these are relatively short lists, you can sort at the app layer.

Best,
Erick

On Thu, Mar 12, 2015 at 2:16 AM, Johannes Siegert
<jo...@marktjagd.de> wrote:
> Hi,
>
> i want to sort my documents by a given order. The order is defined by a list
> of ids.
>
> My current solution is:
>
> list of ids: 15, 5, 1, 10, 3
>
> query: q=*:*&fq=(id:((15) OR (5) OR (1) OR (10) OR
> (3)))&sort=query($idqsort) desc,id asc&idqsort=id:((15^5) OR (5^4) OR (1^3)
> OR (10^2) OR (3^1))&start=0&rows=5
>
> Do you know an other solution to sort by a list of ids?
>
> Thanks!
>
> Johannes