Why am I able to sort on a multiValued field?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why am I able to sort on a multiValued field?

Andy C
I am adding a new float field to my index that I want to perform range
searches and sorting on. It will only contain a single value.

I have an existing dynamic field definition in my schema.xml that I wanted
to use to avoid having to updating the schema:

    <fieldType name="pfloat" class="solr.FloatPointField" docValues="true"/>
    <dynamicField name="*_float"  type="pfloat"  indexed="true"
 stored="true" multiValued="true"/>

I went ahead and implemented this in a test system (recently updated to
Solr 8.7), but then it occurred to me that I am not going to be able to
sort on the field because it is defined as multiValued.

But to my surprise sorting worked, and gave the expected results.Why? Can
this behavior be relied on in future releases?

Appreciate any insights.

Thanks
- AndyC -
Reply | Threaded
Open this post in threaded view
|

Re: Why am I able to sort on a multiValued field?

Erick Erickson
From the “Common Query Paramters” (sort) section of the ref guide:

"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.”

Best,
Erick

> On Nov 13, 2020, at 4:36 PM, Andy C <[hidden email]> wrote:
>
> I am adding a new float field to my index that I want to perform range
> searches and sorting on. It will only contain a single value.
>
> I have an existing dynamic field definition in my schema.xml that I wanted
> to use to avoid having to updating the schema:
>
>    <fieldType name="pfloat" class="solr.FloatPointField" docValues="true"/>
>    <dynamicField name="*_float"  type="pfloat"  indexed="true"
> stored="true" multiValued="true"/>
>
> I went ahead and implemented this in a test system (recently updated to
> Solr 8.7), but then it occurred to me that I am not going to be able to
> sort on the field because it is defined as multiValued.
>
> But to my surprise sorting worked, and gave the expected results.Why? Can
> this behavior be relied on in future releases?
>
> Appreciate any insights.
>
> Thanks
> - AndyC -