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 Rok Rejc <ro...@gmail.com> on 2014/03/19 14:05:37 UTC

Sort by exact match

Hi all,

I have a field in the index - lets call it Name. Name can have one or more
words. I want to query all documents which match by name (full or partial
match), and order the results:
- first display result(s) with exact matches
- after that display results with partial matched and order them
alphabeticaly

To achive this I have created two Name fields in the index:
- NameUnTokenized which uses KeywordTokenizer and
- NameTokenized which uses StandardTokenizer

But now I have no clue how to write a query. Is this possible with standard
query and sort functions?  How?

Other option is to write a custom plugin which will perform two queries and
merge results (that shouldn't be a problem).

Many thanks in advance.

Re: Sort by exact match

Posted by Erick Erickson <er...@gmail.com>.
Sorting applies to the entire result set,
there's no notion of "sort some docs one
way and sort others another way". So
I don't know any OOB way to do what
you want.

I don't know what your response time
requirements are, but you could do this
by firing off two queries and collating
the results. If the performance is
acceptable, it would be faster to code
than writing a custom plugin, which would
probably do much the same thing anyway.

The second query wouldn't have to fire
if the first one returned a page full of results...

FWIW,
Erick

On Wed, Mar 19, 2014 at 6:05 AM, Rok Rejc <ro...@gmail.com> wrote:
> Hi all,
>
> I have a field in the index - lets call it Name. Name can have one or more
> words. I want to query all documents which match by name (full or partial
> match), and order the results:
> - first display result(s) with exact matches
> - after that display results with partial matched and order them
> alphabeticaly
>
> To achive this I have created two Name fields in the index:
> - NameUnTokenized which uses KeywordTokenizer and
> - NameTokenized which uses StandardTokenizer
>
> But now I have no clue how to write a query. Is this possible with standard
> query and sort functions?  How?
>
> Other option is to write a custom plugin which will perform two queries and
> merge results (that shouldn't be a problem).
>
> Many thanks in advance.