You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by ian parkin <ia...@yahoo.com> on 2005/07/06 19:46:22 UTC

Help with custom sorting - ignoring case on string fields.

Hello Folks,

Previously, I was using version 1.3 of Lucene that had no complex
sorting abilities, so I wrote my own code to do this using a TreeMap
and Comparator. The sorting was basically lower case comparisons of
strings with a few extra little tweaks here and there.

This past weekend I upgraded to 1.4.3 of Lucene and am looking for
some help with custom sorting code. 

My application stores a couple of mixed-case text fields 'author' and
'title' as Field.Text and I would like to sort on these fields in a
case insensitive manner.

I have been looking at the DistanceComparatorSource example in the
'Lucene In Action' book and have been trying to adapt that to my
humble needs, but so far no luck. For some reason, I just can't get
my head round the example in order to tailor it to my needs.

Does anyone have any example ComparatorSource code that sorts strings
ignoring the case ?

Thanks

IAP

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Help with custom sorting - ignoring case on string fields.

Posted by ian parkin <ia...@yahoo.com>.
Thanks for the reply. 

I actually implemented what you suggested - storing lower case fields
- earlier today and it works quite nicely.

I'll certainly review my use of the Field.Text.

IAP

--- Erik Hatcher <er...@ehatchersolutions.com> wrote:

> Ian - I'll look into this issue in more detail as soon as I can,
> but  
> one reasonable approach is to add a special field designed for  
> sorting that has all case normalized to either all upper or all
> lower  
> such that sorting is case insensitive.  Note that Field.Text is not
> a  
> good choice for sorting, as it is highly likely there would be  
> multiple terms for that field which does not work with sorting.  
> See  
> the javadocs for Sort:
> 
>     
> http://lucene.apache.org/java/docs/api/org/apache/lucene/search/ 
> Sort.html
> 
> So given this, a think a special field for sorting that has been  
> lowercased but uses a non-tokenized but indexed field type is the  
> best choice.
> 
> Erik
> 
> On Jul 6, 2005, at 1:46 PM, ian parkin wrote:
> 
> > Hello Folks,
> >
> > Previously, I was using version 1.3 of Lucene that had no complex
> > sorting abilities, so I wrote my own code to do this using a
> TreeMap
> > and Comparator. The sorting was basically lower case comparisons
> of
> > strings with a few extra little tweaks here and there.
> >
> > This past weekend I upgraded to 1.4.3 of Lucene and am looking
> for
> > some help with custom sorting code.
> >
> > My application stores a couple of mixed-case text fields 'author'
> and
> > 'title' as Field.Text and I would like to sort on these fields in
> a
> > case insensitive manner.
> >
> > I have been looking at the DistanceComparatorSource example in
> the
> > 'Lucene In Action' book and have been trying to adapt that to my
> > humble needs, but so far no luck. For some reason, I just can't
> get
> > my head round the example in order to tailor it to my needs.
> >
> > Does anyone have any example ComparatorSource code that sorts
> strings
> > ignoring the case ?
> >
> > Thanks
> >
> > IAP
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Help with custom sorting - ignoring case on string fields.

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Ian - I'll look into this issue in more detail as soon as I can, but  
one reasonable approach is to add a special field designed for  
sorting that has all case normalized to either all upper or all lower  
such that sorting is case insensitive.  Note that Field.Text is not a  
good choice for sorting, as it is highly likely there would be  
multiple terms for that field which does not work with sorting.   See  
the javadocs for Sort:

     http://lucene.apache.org/java/docs/api/org/apache/lucene/search/ 
Sort.html

So given this, a think a special field for sorting that has been  
lowercased but uses a non-tokenized but indexed field type is the  
best choice.

Erik

On Jul 6, 2005, at 1:46 PM, ian parkin wrote:

> Hello Folks,
>
> Previously, I was using version 1.3 of Lucene that had no complex
> sorting abilities, so I wrote my own code to do this using a TreeMap
> and Comparator. The sorting was basically lower case comparisons of
> strings with a few extra little tweaks here and there.
>
> This past weekend I upgraded to 1.4.3 of Lucene and am looking for
> some help with custom sorting code.
>
> My application stores a couple of mixed-case text fields 'author' and
> 'title' as Field.Text and I would like to sort on these fields in a
> case insensitive manner.
>
> I have been looking at the DistanceComparatorSource example in the
> 'Lucene In Action' book and have been trying to adapt that to my
> humble needs, but so far no luck. For some reason, I just can't get
> my head round the example in order to tailor it to my needs.
>
> Does anyone have any example ComparatorSource code that sorts strings
> ignoring the case ?
>
> Thanks
>
> IAP
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org