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 Simon Kahl <si...@gmail.com> on 2007/04/20 19:05:46 UTC

sorting by matched field, then title alpha

Hi.  I have some result ordering requirements which I can not solve
searching the doco and forums to this point.  Perhaps what I am trying does
not belong in solr.  Can anyone offer any hint or suggestion before I
disappear into a vortex of terror?

I need to conditionally order results of phrase searches like this:
* First show all docs with phrase in field A - regardless of other
occurences of phrase in doc - ordered alphabetically by field X
* Next show all docs with phrase in field B - ... (as above)
* Then same again for fields C, D and E
* Then show remaining matching docs as per default scoring

Perhaps I will have to do this clientside (ie. do multiple searches and
concatenate results), but I'm hoping there is some way I can do this in a
single search.

Thanks,
Simon

Re: sorting by matched field, then title alpha

Posted by Chris Hostetter <ho...@fucit.org>.
: Think I will have to modify o.a.s.s.QueryParsing.parseSort to hook in custom
: sort.  Is there any better way?

If you write a custom SortComparatorSource, then the easiest way to use it
would probably be to write your own subclass of TextField and override the
getSortField method to construct a SortField that uses it.



-Hoss


Re: sorting by matched field, then title alpha

Posted by Simon Kahl <si...@gmail.com>.
>
> You can approximate it by doing something like:
> A:"phrase"^100000 B:"phrase"^10000 C:"phrase"^1000 D:"phrase"^100
> E:"phrase"^30 <rest of query>
>

Thanks for suggestion Mike.  I tried boosting like this but all docs get
slightly different scores (because of tf, idf etc) and so secondary sort on
field X has no impact.  I'm thinking now I will try a custom
SortComparatorSource impl (based on DistanceComparatorSource in Lucene In
Action) using fixed values corresponding to matches in field A, B or C etc.
Will then use that as primary sort followed by the secondary sort on field
X.

Think I will have to modify o.a.s.s.QueryParsing.parseSort to hook in custom
sort.  Is there any better way?

Kind Regards,
Simon

Re: sorting by matched field, then title alpha

Posted by Mike Klaas <mi...@gmail.com>.
On 4/20/07, Simon Kahl <si...@gmail.com> wrote:

> I need to conditionally order results of phrase searches like this:
> * First show all docs with phrase in field A - regardless of other
> occurences of phrase in doc - ordered alphabetically by field X
> * Next show all docs with phrase in field B - ... (as above)
> * Then same again for fields C, D and E
> * Then show remaining matching docs as per default scoring
>
> Perhaps I will have to do this clientside (ie. do multiple searches and
> concatenate results), but I'm hoping there is some way I can do this in a
> single search.

You can approximate it by doing something like:
A:"phrase"^100000 B:"phrase"^10000 C:"phrase"^1000 D:"phrase"^100
E:"phrase"^30 <rest of query>

HTH,
-Mike