lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Toke Eskildsen ...@statsbiblioteket.dk>
Subject RE: Lucene search result produced wrong result (due to java Collation)?
Date Tue, 01 Mar 2011 07:33:38 GMT
On Mon, 2011-02-28 at 22:44 +0100, Zhang, Lisheng wrote:
> Very sorry I made a typo, what I meant to say is that lucene sort produced wrong
> result in English names (String ASC):
> 
> liu yu
> l yy

The standard Java Collator ignores whitespace. It can be hacked, but you
will have to write your own implementation to get Lucene to sort in the
desired way. FieldComparatorSource is a good place to start.

A code snippet demonstrating the Collator-hack:

    public void testJavaStandardCollator() throws Exception {
        java.text.Collator javaC =
            java.text.Collator.getInstance(new Locale("EN"));
        assertTrue("Spaces should be ignored per default",
                   javaC.compare("liu yu", "l yy") < 0);

        java.text.RuleBasedCollator adjustedC = new
java.text.RuleBasedCollator(
                ((java.text.RuleBasedCollator)javaC).getRules().
                    replace("<'\u005f'", "<' '<'\u005f'"));
        assertTrue("Spaces should be significant inside strings after
adjust",
                   adjustedC.compare("liu yu", "l yy") > 0);
    }


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


Mime
View raw message