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 Aleksander Akerø <so...@gmail.com> on 2012/08/14 14:53:26 UTC

Facet sort numeric values

Hi

 

I'm having a problem with sorting facets. I am using the facet.sort=index
parameter and it works fine for most of the values.

But for numeric values the sorting goes a bit off.

 

Eksample, when sorting "15, 6, 23, 7, 10, 90" it sorts like this: "10, 15,
23, 6, 7, 90", but what I wanted was "6, 7, 10, 15, 23, 90".

I do understand why it is done so but I would need a fix. I could apply a
fix in the search interface for these particular values but I would prefer
not to.

 

Have anyone had the same problem or have any ideas for me?

 

Thank you!

 

Aleksander Akerø

Systemutvikler

Mobil: 944 89 054

E-post:  <ma...@gurusoft.no> aleksander@gurusoft.no

 

Gurusoft AS

Telefon: 92 44 09 99

Østre Kullerød 5, 3241 Sandefjord

www.gurusoft.no

 <http://goo.gl/bKzvX> Description: QR-Kontaktinfo

 


RE: Facet sort numeric values

Posted by Aleksander Akerø <so...@gmail.com>.
I see the problem, but there are no possibilities for normalization as the
upper limit could be anything in different cases (hard to explain).
I think it is better for me to just apply the correct type of sorting with
an array/list with some script. This is just for getting the facet values to
look pretty in a filter menu.

I knew this question was a shot in the dark, but thank you for a nice
explanation and possible solution!

Aleksander Akerø
@ Gurusoft AS
Mobil: 944 89 054 
QR-Code (Kontaktinfo)

-----Original Message-----
From: Erick Erickson [mailto:erickerickson@gmail.com] 
Sent: 15. august 2012 19:00
To: solr-user@lucene.apache.org
Subject: Re: Facet sort numeric values

the problem you're running into is that lexical ordering of numeric data !=
numeric ordering. If you have a mixed alpha and numeric data, you man not
care if the alpha stuff is first, i.e.

asdb456
asdf490

sorts fine. Problems happen with
9jsdf
100ukel

the 100ukel comes first.

So if you have a mixed alpha and numeric situation, you have to either live
with it or normalize the numeric data so it lexical ordering == numeric
ordering, the most common way is to left-pad numeric data to a fixed-width,
i.e. rather than index asb9fg, index asb0000009fg. Of course you have to
know what the upper limit of any digit is for this to work...

Best
Erick

On Wed, Aug 15, 2012 at 12:33 AM, Aleksander Akerø
<so...@gmail.com> wrote:
> Oh brilliant, didn't think of it being possible to configure that way.
>
> Had made my own "untokenized" type, so I guess it would be better for 
> me to control datatype this way.
>
> Bonus question (hehe): What if these field values also contain 
> alphanumeric values? E.g. "Alpha, Bravo, Omega, ... "
> How would this affect the sorting? I guess the TrieIntField is not 
> applicable then.
>
> Aleksander Akerø
> @ Gurusoft AS
> Mobil: 944 89 054
> QR-Code (Kontaktinfo)
>
> -----Original Message-----
> From: Chris Hostetter [mailto:hossman_lucene@fucit.org]
> Sent: 14. august 2012 17:45
> To: solr-user@lucene.apache.org
> Subject: Re: Facet sort numeric values
>
>
> : I'm having a problem with sorting facets. I am using the 
> facet.sort=index
> : parameter and it works fine for most of the values.
>         ...
> : Eksample, when sorting "15, 6, 23, 7, 10, 90" it sorts like this: 
> "10, 15,
> : 23, 6, 7, 90", but what I wanted was "6, 7, 10, 15, 23, 90".
>
> what field type are you using?
>
> If you use one of the Trie___Field types then the facet values should 
> sort exactly as you describe.
>
> <fieldType name="int" class="solr.TrieIntField" precisionStep="0"
> positionIncrementGap="0"/> <fieldType name="float"
> class="solr.TrieFloatField" precisionStep="0" 
> positionIncrementGap="0"/> <fieldType name="long"
class="solr.TrieLongField" precisionStep="0"
> positionIncrementGap="0"/> <fieldType name="double"
> class="solr.TrieDoubleField" precisionStep="0" 
> positionIncrementGap="0"/>
>
>
>
> -Hoss
>


Re: Facet sort numeric values

Posted by Erick Erickson <er...@gmail.com>.
the problem you're running into is that lexical ordering of
numeric data != numeric ordering. If you have a mixed
alpha and numeric data, you man not care if the alpha
stuff is first, i.e.

asdb456
asdf490

sorts fine. Problems happen with
9jsdf
100ukel

the 100ukel comes first.

So if you have a mixed alpha and numeric situation,
you have to either live with it or normalize the numeric
data so it lexical ordering == numeric ordering, the most
common way is to left-pad numeric data to a fixed-width,
i.e. rather than index asb9fg, index asb0000009fg. Of
course you have to know what the upper limit of any digit
is for this to work...

Best
Erick

On Wed, Aug 15, 2012 at 12:33 AM, Aleksander Akerø
<so...@gmail.com> wrote:
> Oh brilliant, didn't think of it being possible to configure that way.
>
> Had made my own "untokenized" type, so I guess it would be better for me to
> control datatype this way.
>
> Bonus question (hehe): What if these field values also contain alphanumeric
> values? E.g. "Alpha, Bravo, Omega, ... "
> How would this affect the sorting? I guess the TrieIntField is not
> applicable then.
>
> Aleksander Akerø
> @ Gurusoft AS
> Mobil: 944 89 054
> QR-Code (Kontaktinfo)
>
> -----Original Message-----
> From: Chris Hostetter [mailto:hossman_lucene@fucit.org]
> Sent: 14. august 2012 17:45
> To: solr-user@lucene.apache.org
> Subject: Re: Facet sort numeric values
>
>
> : I'm having a problem with sorting facets. I am using the facet.sort=index
> : parameter and it works fine for most of the values.
>         ...
> : Eksample, when sorting "15, 6, 23, 7, 10, 90" it sorts like this: "10, 15,
> : 23, 6, 7, 90", but what I wanted was "6, 7, 10, 15, 23, 90".
>
> what field type are you using?
>
> If you use one of the Trie___Field types then the facet values should sort
> exactly as you describe.
>
> <fieldType name="int" class="solr.TrieIntField" precisionStep="0"
> positionIncrementGap="0"/> <fieldType name="float"
> class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
> <fieldType name="long" class="solr.TrieLongField" precisionStep="0"
> positionIncrementGap="0"/> <fieldType name="double"
> class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
>
>
>
> -Hoss
>

RE: Facet sort numeric values

Posted by Aleksander Akerø <so...@gmail.com>.
Oh brilliant, didn't think of it being possible to configure that way.

Had made my own "untokenized" type, so I guess it would be better for me to
control datatype this way.

Bonus question (hehe): What if these field values also contain alphanumeric
values? E.g. "Alpha, Bravo, Omega, ... "
How would this affect the sorting? I guess the TrieIntField is not
applicable then.

Aleksander Akerø
@ Gurusoft AS
Mobil: 944 89 054 
QR-Code (Kontaktinfo)

-----Original Message-----
From: Chris Hostetter [mailto:hossman_lucene@fucit.org] 
Sent: 14. august 2012 17:45
To: solr-user@lucene.apache.org
Subject: Re: Facet sort numeric values


: I'm having a problem with sorting facets. I am using the facet.sort=index
: parameter and it works fine for most of the values.
	...
: Eksample, when sorting "15, 6, 23, 7, 10, 90" it sorts like this: "10, 15,
: 23, 6, 7, 90", but what I wanted was "6, 7, 10, 15, 23, 90".

what field type are you using?

If you use one of the Trie___Field types then the facet values should sort
exactly as you describe.

<fieldType name="int" class="solr.TrieIntField" precisionStep="0"
positionIncrementGap="0"/> <fieldType name="float"
class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0"
positionIncrementGap="0"/> <fieldType name="double"
class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>



-Hoss


Re: Facet sort numeric values

Posted by Chris Hostetter <ho...@fucit.org>.
: I'm having a problem with sorting facets. I am using the facet.sort=index
: parameter and it works fine for most of the values.
	...
: Eksample, when sorting "15, 6, 23, 7, 10, 90" it sorts like this: "10, 15,
: 23, 6, 7, 90", but what I wanted was "6, 7, 10, 15, 23, 90".

what field type are you using?

If you use one of the Trie___Field types then the facet values should sort 
exactly as you describe.

<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>



-Hoss