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 Rohan Thakur <ro...@gmail.com> on 2013/05/22 14:56:42 UTC

Sorting solr search results using multiple fields

hi all

I wanted to know is there a way I can sort the my documents based on 3
fields
I have fields like pop(which is basically frequency of the term searched
history) and autosug(auto suggested words) and initial_boost(copy field of
autosug such that only match with initial term match having
whole sentence saved as one token)

Now I want the documents to be returned as:


   1. initial_boost with pop of 192
   2. initial_boost with pop of 156
   3. initial_boost with pop of 120
   4. autosug with pop of 205
   5. autosug with pop of 180
   6. autosug with pop of 112

I have tried using boosting the initial_boost field but without the sort it
does the above boost to the initial_boost than autosug but as I add sort=pop
desc documents gets sorted according to pop field disturbing the boost on
the fields that I had set.
help anyone...

thanks in advance.
regards
Rohan

Re: Sorting solr search results using multiple fields

Posted by Rohan Thakur <ro...@gmail.com>.
k thanks gora

that what I was thinking but thought I should ask as there might be some
solution in solr it self...the last option fine I would go with that only.

thanks
rohan


On Thu, May 23, 2013 at 9:13 AM, Gora Mohanty <go...@mimirtech.com> wrote:

> On 22 May 2013 19:37, Rohan Thakur <ro...@gmail.com> wrote:
> [...]
> >  this inital_boost is basically copy field of autosug but saved using
> > different analysers taking whole sentence as single token and generating
> > edge ngrams so that what I search on this field only term matching from
> > first will match...and for any other infix term match I have autosug
> > field....
> >
> > so now what I want from this is to show the documents returned with
> > initial_boost first and then the documents with autosug field sorted with
> > pop field respectively (separately) and return the result...
> >
> > now from your suggestion I could do this using   sort on multiple fields
> by
> > separating them by
> > commas, as described under
> > http://wiki.apache.org/solr/CommonQueryParameters#sort
> >
> > but for that I would require 1 field having value greater(all equal say
> 2)
> > for initial_boost field and smaller(all same say 1) for autosug field how
> > can I do this? or is there some better solution..
>
> Um, maybe it would help if you started out by explaining
> what you are trying to do instead of changing the requirements
> after a solution is proposed.
>
> The above design seems faulty. If the fields have the same
> values, there is no way to sort them differently. Boosts are
> not guaranteed to always promote documents in the
> desired manner, and will not work with sorting in any case.
> You can try to kludge things together in various ways, e.g.,
> * Add a prefix so that some fields always sort first, e.g.,
>   prefix "aaa..." to a string field to try and ensure that it
>   sorts first
> * Have not tried this, but it should be possible to use a
>   Solr function query with a function that sorts by the
>   field name: http://wiki.apache.org/solr/FunctionQuery
>
> As you seem to be using analysers on the fields, beware
> that sorting will not work reliably on multi-valued or tokenised
> fields.
>
> You could also index different fields to different Solr cores,
> fetch the results for individual fields with separate queries,
> and combine them as desired. This might be the cleanest,
> if not the most efficient, solution.
>
> Regards,
> Gora
>

Re: Sorting solr search results using multiple fields

Posted by Gora Mohanty <go...@mimirtech.com>.
On 22 May 2013 19:37, Rohan Thakur <ro...@gmail.com> wrote:
[...]
>  this inital_boost is basically copy field of autosug but saved using
> different analysers taking whole sentence as single token and generating
> edge ngrams so that what I search on this field only term matching from
> first will match...and for any other infix term match I have autosug
> field....
>
> so now what I want from this is to show the documents returned with
> initial_boost first and then the documents with autosug field sorted with
> pop field respectively (separately) and return the result...
>
> now from your suggestion I could do this using   sort on multiple fields by
> separating them by
> commas, as described under
> http://wiki.apache.org/solr/CommonQueryParameters#sort
>
> but for that I would require 1 field having value greater(all equal say 2)
> for initial_boost field and smaller(all same say 1) for autosug field how
> can I do this? or is there some better solution..

Um, maybe it would help if you started out by explaining
what you are trying to do instead of changing the requirements
after a solution is proposed.

The above design seems faulty. If the fields have the same
values, there is no way to sort them differently. Boosts are
not guaranteed to always promote documents in the
desired manner, and will not work with sorting in any case.
You can try to kludge things together in various ways, e.g.,
* Add a prefix so that some fields always sort first, e.g.,
  prefix "aaa..." to a string field to try and ensure that it
  sorts first
* Have not tried this, but it should be possible to use a
  Solr function query with a function that sorts by the
  field name: http://wiki.apache.org/solr/FunctionQuery

As you seem to be using analysers on the fields, beware
that sorting will not work reliably on multi-valued or tokenised
fields.

You could also index different fields to different Solr cores,
fetch the results for individual fields with separate queries,
and combine them as desired. This might be the cleanest,
if not the most efficient, solution.

Regards,
Gora

Re: Sorting solr search results using multiple fields

Posted by Rohan Thakur <ro...@gmail.com>.
thanks gora I got that....
one more thing
what actually I have done is made document consisting of fields:

{
        "autosug":"galaxy",
        "query_id":1414,
        "pop":168,

        "initial_boost":"galaxy"

        "_version_":1435669695565922305,

"score":1.8908522}

 this inital_boost is basically copy field of autosug but saved using
different analysers taking whole sentence as single token and generating
edge ngrams so that what I search on this field only term matching from
first will match...and for any other infix term match I have autosug
field....

so now what I want from this is to show the documents returned with
initial_boost first and then the documents with autosug field sorted with
pop field respectively (separately) and return the result...

now from your suggestion I could do this using   sort on multiple fields by
separating them by
commas, as described under
http://wiki.apache.org/solr/CommonQueryParameters#sort

but for that I would require 1 field having value greater(all equal say 2)
for initial_boost field and smaller(all same say 1) for autosug field how
can I do this? or is there some better solution..

thanks
regards
Rohan


On Wed, May 22, 2013 at 6:39 PM, Gora Mohanty <go...@mimirtech.com> wrote:

> On 22 May 2013 18:26, Rohan Thakur <ro...@gmail.com> wrote:
> > hi all
> >
> > I wanted to know is there a way I can sort the my documents based on 3
> > fields
> > I have fields like pop(which is basically frequency of the term searched
> > history) and autosug(auto suggested words) and initial_boost(copy field
> of
> > autosug such that only match with initial term match having
> > whole sentence saved as one token)
> [...]
>
> You seem to be confusing boosting with sorting. If you
> sort the results, the boosts are irrelevant.
>
> You can sort on multiple fields by separating them by
> commas, as described under
> http://wiki.apache.org/solr/CommonQueryParameters#sort
>
> Regards,
> Gora
>

Re: Sorting solr search results using multiple fields

Posted by Gora Mohanty <go...@mimirtech.com>.
On 22 May 2013 18:26, Rohan Thakur <ro...@gmail.com> wrote:
> hi all
>
> I wanted to know is there a way I can sort the my documents based on 3
> fields
> I have fields like pop(which is basically frequency of the term searched
> history) and autosug(auto suggested words) and initial_boost(copy field of
> autosug such that only match with initial term match having
> whole sentence saved as one token)
[...]

You seem to be confusing boosting with sorting. If you
sort the results, the boosts are irrelevant.

You can sort on multiple fields by separating them by
commas, as described under
http://wiki.apache.org/solr/CommonQueryParameters#sort

Regards,
Gora