lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Aroush" <>
Subject Locale string compare: Java vs. C#
Date Thu, 14 Dec 2006 02:20:26 GMT
Hi folks,

Over at Lucene.Net, I have run into a NUnit test which is failing with
Lucene.Net (C#) but is passing with Lucene (Java).  The two tests that fail
are: TestInternationalMultiSearcherSort and TestInternationalSort

After several hours of investigation, I narrowed the problem to what I
believe is a difference in the way Java and .NET implement compare.

The code in question is this method (found in

    public final int compare (final ScoreDoc i, final ScoreDoc j) {
        return (index[i.doc], index[j.doc]);

To demonstrate the compare problem (Java vs. .NET) I crated this simple code
both in Java and C#:

    // Java code: you get back 1 for 'res'
    String s1 = "H\u00D8T";
    String s2 = "HUT";
    Collator collator = Collator.getInstance (Locale.US);
    int diff =, s2);

    // C# code: you get back -1 for 'res'
    string s1 = "H\u00D8T";
    string s2 = "HUT";
    System.Globalization.CultureInfo locale = new
    System.Globalization.CompareInfo collator = locale.CompareInfo;
    int res = collator.Compare(s1, s2);

Java will give me back a 1 while .NET gives me back -1.

So, what I am trying to figure out is who is doing the right thing?  Or am I
missing additional calls before I can compare?

My goal is to understand why the difference exist and thus based on that
understanding I can judge how serious this issue is and find a fix for it or
just document it as a language difference between Java and .NET.

Btw, this is based on Lucene 2.0 for both Java and C# Lucene.


-- George Aroush

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message