Sorting multi-valued fields

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting multi-valued fields

richard.clarke
Hi
What does it mean to sort documents by a multivalued field?  If a field has
multiple values, how can this be used to sort documents?

e.g. if document 1 has a numeric field containing values 1,2,3,4,5 and
document 2 has values in the same field of 1,2,3 - which come first in the
sort order and why?

Thanks in advance.



--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Reply | Threaded
Open this post in threaded view
|

Re: Sorting multi-valued fields

Mikhail Khludnev-2
http://people.apache.org/~mkhl/searchable-solr-guide-7-3/common-query-parameters.html#sort-parameter
In the case of primitive fields, or SortableTextFields, that are
multiValued="true" the representative value used for each doc when sorting
depends on the sort direction: The minimum value in each document is used
for ascending (asc) sorting, while the maximal value in each document is
used for descending (desc) sorting. This default behavior is equivilent to
explicitly sorting using the 2 argument field()
<http://people.apache.org/~mkhl/searchable-solr-guide-7-3/function-queries.html#field-function>
 function: sort=field(name,min) asc and sort=field(name,max) desc

On Fri, Sep 14, 2018 at 1:50 PM richard.clarke <[hidden email]>
wrote:

> Hi
> What does it mean to sort documents by a multivalued field?  If a field has
> multiple values, how can this be used to sort documents?
>
> e.g. if document 1 has a numeric field containing values 1,2,3,4,5 and
> document 2 has values in the same field of 1,2,3 - which come first in the
> sort order and why?
>
> Thanks in advance.
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
>


--
Sincerely yours
Mikhail Khludnev
Reply | Threaded
Open this post in threaded view
|

Re: Sorting multi-valued fields

Shawn Heisey-2
In reply to this post by richard.clarke
On 9/14/2018 4:50 AM, richard.clarke wrote:
> What does it mean to sort documents by a multivalued field?  If a field has
> multiple values, how can this be used to sort documents?
>
> e.g. if document 1 has a numeric field containing values 1,2,3,4,5 and
> document 2 has values in the same field of 1,2,3 - which come first in the
> sort order and why?

It's my understanding that Solr will refuse to sort on a multivalued
field, returning an error.  If Solr were to make a decision to use the
first value, or the minimum value, or the maximum value ... some users
would think that was the wrong choice.

You can use a function query to have it sort on the min or max value of
a field.

https://lucidworks.com/2015/09/10/minmax-on-multivalued-field/

Thanks,
Shawn