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 Luis Cappa Banda <lu...@gmail.com> on 2012/03/02 10:13:02 UTC

A sorting question.

Hello!

Just a brief question. I'm querying by my docs ids to retrieve the whole
document data from them, and I would like to retrieve them in the same
order as I queried. Example:

*q*=id:(A+OR+B+OR+C+OR...)

And I would like to get a response with a default order like:

response:

    *docA*:{

             }


    *docB*:{

             }


    *docC*:{

             }

    Etc.


The default response get the documents in a different order, I supose that
due to Solr internal score algorithm. The ids are not numeric, so there is
no option to order them with a numeric logic. Any suggestion?

Thanks a lot!



Luis Cappa.

Re: A sorting question.

Posted by Luis Cappa Banda <lu...@gmail.com>.
Sometimes the solution is so easy that  I can't see it in front of me.

Thanks, Mikhail!

2012/3/3 Mikhail Khludnev <mk...@griddynamics.com>

> Hi Luis,
>
> Do you mean
>
> q=id:(A^10+OR+B^9+OR+C^8+OR...)
> I'm not sure whether it woks but
>
> q=id:A^10+OR+id:B^9+OR+id:C^8+OR...)
>
> definitely does
>
> On Fri, Mar 2, 2012 at 1:13 PM, Luis Cappa Banda <luiscappa@gmail.com
> >wrote:
>
> > Hello!
> >
> > Just a brief question. I'm querying by my docs ids to retrieve the whole
> > document data from them, and I would like to retrieve them in the same
> > order as I queried. Example:
> >
> > *q*=id:(A+OR+B+OR+C+OR...)
> >
> > And I would like to get a response with a default order like:
> >
> > response:
> >
> >    *docA*:{
> >
> >             }
> >
> >
> >    *docB*:{
> >
> >             }
> >
> >
> >    *docC*:{
> >
> >             }
> >
> >    Etc.
> >
> >
> > The default response get the documents in a different order, I supose
> that
> > due to Solr internal score algorithm. The ids are not numeric, so there
> is
> > no option to order them with a numeric logic. Any suggestion?
> >
> > Thanks a lot!
> >
> >
> >
> > Luis Cappa.
> >
>
>
>
> --
> Sincerely yours
> Mikhail Khludnev
> Lucid Certified
> Apache Lucene/Solr Developer
> Grid Dynamics
>
> <http://www.griddynamics.com>
>  <mk...@griddynamics.com>
>

Re: A sorting question.

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Hi Luis,

Do you mean

q=id:(A^10+OR+B^9+OR+C^8+OR...)
I'm not sure whether it woks but

q=id:A^10+OR+id:B^9+OR+id:C^8+OR...)

definitely does

On Fri, Mar 2, 2012 at 1:13 PM, Luis Cappa Banda <lu...@gmail.com>wrote:

> Hello!
>
> Just a brief question. I'm querying by my docs ids to retrieve the whole
> document data from them, and I would like to retrieve them in the same
> order as I queried. Example:
>
> *q*=id:(A+OR+B+OR+C+OR...)
>
> And I would like to get a response with a default order like:
>
> response:
>
>    *docA*:{
>
>             }
>
>
>    *docB*:{
>
>             }
>
>
>    *docC*:{
>
>             }
>
>    Etc.
>
>
> The default response get the documents in a different order, I supose that
> due to Solr internal score algorithm. The ids are not numeric, so there is
> no option to order them with a numeric logic. Any suggestion?
>
> Thanks a lot!
>
>
>
> Luis Cappa.
>



-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: A sorting question.

Posted by Chris Hostetter <ho...@fucit.org>.
: problem becomes from MoreLikeThis behaviour. As you probably know that Solr
: feature only suggests similar components by the first - and only - document
: returned from the original query. That is if you have a query that returns
: 5 documents (a query with five IDs with OR boolean clauses, like before)
: MoreLikeThis only returns similar documents for the first one.

that's how the MLT *Handler* works, but if you use the MLT *component* it 
will give you N docs similar to *each* doc in the response...

  http://wiki.apache.org/solr/MoreLikeThis

So using the 3.5 example configs/data...

http://localhost:8983/solr/select?q=memory&mlt=true&mlt.count=2&rows=5&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&fl=id,score

...that gives me the fist 5 results matching my query, and for each of 
those 5 results, i get the top 2 results "like" each of the individual 
documents from my main result).

: etc. So now I have to merge the results but, hey! Imagine that you receive
: a sort by Date. You have to compose the final response with the merged
: similar documents and sort it by Date. Thats a problem, right? So I do the
: following:

So it sounds like you want a "more like these" type search ... if query Q 
matchines some set of docs, you want to take the first N docs, and then 
generate a list of M docs similar to those N as a whole?

If i'm understanding correctly, then you might find it easier/better to 
tweak your alogorithm so that you continue to use the MLT *handler* for 
each of your N main docs but instead of looking at the MLT response docs, 
you use mlt.interestingTerms=true and gather up all of the interesting 
terms, then issue one single query where you search for all of those 
interesting terms and see what final set of documents you get back.

As for your original problem (assuming neither of those previous 
comments ar helpful)....

: The number of documents is not important. Imagine that you have a rows=20,
: so N=20 and you have and array of 20 similar components ordered correctly
: from most important to less important. Returning to the sorting problem, if
: you launch another and final query to Solr with q=(all the similar document
: IDs ordered) you can append the original sorting by Date, so the results
: can be sorted by Date, or by other field, or just without order... and
: that´s the problem!

...the easiest way i can think of to deal with this is to ignore the sort 
completely.  you're asking for all the docs you want by id and setting 
rows big enough to get them all at once so you know they will all be 
returned on page one, and you know thye have a uniqueKey field (you are 
quering on it) so just make sure "id" in in your "fl" param when you get 
them all back, look at the "id" field and order them they way you want in 
your client code.



-Hoss

Re: A sorting question.

Posted by Luis Cappa Banda <lu...@gmail.com>.
Hi, Erick!

And thank you for answering! You always answer my questions, :-) Well, I´ll
try to explain better, because the context is more complex. The original
problem becomes from MoreLikeThis behaviour. As you probably know that Solr
feature only suggests similar components by the first - and only - document
returned from the original query. That is if you have a query that returns
5 documents (a query with five IDs with OR boolean clauses, like before)
MoreLikeThis only returns similar documents for the first one.

Thats very frustrating, and I tried to solve it partially - and not very
efficiently. I´ve got an intermediate business logic that manages querys
from the front-end and Solr architecture. This components defines and API
of queries and pre and post processors to execute with it. The thing is
that I want to return similar documents for, for example, five documents
queried. Due to MoreLikeThis limitations I do this:

1. First MoreLikeThis query for the first document. I get all the similar
documents.
2. Second MoreLikeThis query for the second document. I get all the similar
documents.
  ...
5. Fith MoreLikeThis query for the fith document. I get all the similar
documents.

I have to notice that the order of the query is important. I mean that the
first ID is the first ID because its more important that the second ID,
etc. So now I have to merge the results but, hey! Imagine that you receive
a sort by Date. You have to compose the final response with the merged
similar documents and sort it by Date. Thats a problem, right? So I do the
following:

1. Get first similar document ID from the first ID response.
2. Get the first similar document ID  from the second ID response.
  ...
3. Get the first similar document ID  from the fith ID response.
4. Get the second similar document ID  from the first ID response.
  ....
N. Get the N similar document ID  from the fith ID response.


The number of documents is not important. Imagine that you have a rows=20,
so N=20 and you have and array of 20 similar components ordered correctly
from most important to less important. Returning to the sorting problem, if
you launch another and final query to Solr with q=(all the similar document
IDs ordered) you can append the original sorting by Date, so the results
can be sorted by Date, or by other field, or just without order... and
that´s the problem!

If you don´t indicate any order I hope that the documents will be returned
with the similar documents IDs sorting: I mean from most important to less
important, and you saw what Solr does: returns the documents response with
score sort.

Phew! And that´s all. Ehm... any suggestion? :-D Hehehe.

Thank you so much!



Luis Cappa.

Re: A sorting question.

Posted by Erick Erickson <er...@gmail.com>.
I'm not quite sure what you mean by "order with numeric logic".

You're right, the default ordering is by score. I can't think of anything
that would arbitrarily sort by a varying input string, that is
id:(a OR b OR c OR d) would sort differently than
id:(b OR a OR d Or c).

Perhaps if you outlined the problem you're trying to solve alternate
approaches might be possible...

Best
Erick

On Fri, Mar 2, 2012 at 4:22 AM, Luis Cappa Banda <lu...@gmail.com> wrote:
> The only reference I found is:
>
> http://stackoverflow.com/questions/5753079/solr-query-without-order
>
> Anyone had the same problem? Maybe using a dynamic field could solve this
> issue?
>
> Thanks!
>
>
> Luis Cappa.
>
>
> 2012/3/2 Luis Cappa Banda <lu...@gmail.com>
>
>> Hello!
>>
>> Just a brief question. I'm querying by my docs ids to retrieve the whole
>> document data from them, and I would like to retrieve them in the same
>> order as I queried. Example:
>>
>> *q*=id:(A+OR+B+OR+C+OR...)
>>
>> And I would like to get a response with a default order like:
>>
>> response:
>>
>>     *docA*:{
>>
>>              }
>>
>>
>>     *docB*:{
>>
>>              }
>>
>>
>>     *docC*:{
>>
>>              }
>>
>>     Etc.
>>
>>
>> The default response get the documents in a different order, I supose that
>> due to Solr internal score algorithm. The ids are not numeric, so there is
>> no option to order them with a numeric logic. Any suggestion?
>>
>> Thanks a lot!
>>
>>
>>
>> Luis Cappa.
>>

Re: A sorting question.

Posted by Luis Cappa Banda <lu...@gmail.com>.
The only reference I found is:

http://stackoverflow.com/questions/5753079/solr-query-without-order

Anyone had the same problem? Maybe using a dynamic field could solve this
issue?

Thanks!


Luis Cappa.


2012/3/2 Luis Cappa Banda <lu...@gmail.com>

> Hello!
>
> Just a brief question. I'm querying by my docs ids to retrieve the whole
> document data from them, and I would like to retrieve them in the same
> order as I queried. Example:
>
> *q*=id:(A+OR+B+OR+C+OR...)
>
> And I would like to get a response with a default order like:
>
> response:
>
>     *docA*:{
>
>              }
>
>
>     *docB*:{
>
>              }
>
>
>     *docC*:{
>
>              }
>
>     Etc.
>
>
> The default response get the documents in a different order, I supose that
> due to Solr internal score algorithm. The ids are not numeric, so there is
> no option to order them with a numeric logic. Any suggestion?
>
> Thanks a lot!
>
>
>
> Luis Cappa.
>