You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Netta Steinberg <ns...@dalet.com> on 2022/11/10 10:06:48 UTC

Is there a way to sort alphanumerically?

Hi all,

I want to sort value alphabetically, but also numerically.
Example:
I want that the following items
A1
B4
A2
A19
B10

Will be sorted in the following order
A1
A2
A19
B2
B19

So values that start with A will appear before values that start with B, but also A2 will appear before A19, because the numerical value of 19 is greater then the numerical value of 2.
I've seen similar questions in StackOverflow, but the suggestions were to pad the values with zeros (so, e.g. A2 will become A02) but this is not an option.
All

Thanks,
Netta


Re: Is there a way to sort alphanumerically?

Posted by Andy Webb <an...@gmail.com>.
hi Netta,

How about splitting the values into two new string/pint fields and sorting
on those in sequence? You can keep the original one for display purposes
etc.

HTH,
Andy

On Thu, 10 Nov 2022, 10:07 Netta Steinberg, <ns...@dalet.com> wrote:

> Hi all,
>
> I want to sort value alphabetically, but also numerically.
> Example:
> I want that the following items
> A1
> B4
> A2
> A19
> B10
>
> Will be sorted in the following order
> A1
> A2
> A19
> B2
> B19
>
> So values that start with A will appear before values that start with B,
> but also A2 will appear before A19, because the numerical value of 19 is
> greater then the numerical value of 2.
> I've seen similar questions in StackOverflow, but the suggestions were to
> pad the values with zeros (so, e.g. A2 will become A02) but this is not an
> option.
> All
>
> Thanks,
> Netta
>
>

Re: Is there a way to sort alphanumerically?

Posted by Andrew Hankinson <an...@rism.digital>.
I use this field definition for a sort field:

<fieldType name="sort" class="solr.ICUCollationField" locale="" numeric="true" strength="secondary" alternate="shifted" sortMissingLast="true" />

This seems to work well.

-Andrew

> On 10 Nov 2022, at 11:06, Netta Steinberg <ns...@dalet.com> wrote:
> 
> Hi all,
> 
> I want to sort value alphabetically, but also numerically.
> Example:
> I want that the following items
> A1
> B4
> A2
> A19
> B10
> 
> Will be sorted in the following order
> A1
> A2
> A19
> B2
> B19
> 
> So values that start with A will appear before values that start with B, but also A2 will appear before A19, because the numerical value of 19 is greater then the numerical value of 2.
> I've seen similar questions in StackOverflow, but the suggestions were to pad the values with zeros (so, e.g. A2 will become A02) but this is not an option.
> All
> 
> Thanks,
> Netta
>