Index: src/test/org/apache/lucene/search/TestSort.java
===================================================================
--- src/test/org/apache/lucene/search/TestSort.java	(revision 550409)
+++ src/test/org/apache/lucene/search/TestSort.java	(working copy)
@@ -384,7 +384,25 @@
 		sort.setSort (new SortField ("i18n", new Locale("da", "dk")));
 		assertMatches (multiSearcher, queryY, sort, "BJDHF");
 	} 
-    
+
+        // test custom locale-sort
+        public void testCustomInternationalSort() throws Exception {
+		sort.setSort (new SortField ("i18n", new LocaleBasedSortComparator(Locale.US)));
+		assertMatches (full, queryY, sort, "BFJDH");
+
+		sort.setSort (new SortField ("i18n", new LocaleBasedSortComparator(new Locale("sv", "se"))));
+		assertMatches (full, queryY, sort, "BJDFH");
+
+		sort.setSort (new SortField ("i18n", new LocaleBasedSortComparator(new Locale("da", "dk"))));
+		assertMatches (full, queryY, sort, "BJDHF");
+
+		sort.setSort (new SortField ("i18n", new LocaleBasedSortComparator(Locale.US)));
+		assertMatches (full, queryX, sort, "ECAGI");
+
+		sort.setSort (new SortField ("i18n", new LocaleBasedSortComparator(Locale.FRANCE)));
+		assertMatches (full, queryX, sort, "EACGI");
+	}
+        
 	// test a custom sort function
 	public void testCustomSorts() throws Exception {
 		sort.setSort (new SortField ("custom", SampleComparable.getComparatorSource()));
Index: src/java/org/apache/lucene/search/SortField.java
===================================================================
--- src/java/org/apache/lucene/search/SortField.java	(revision 550409)
+++ src/java/org/apache/lucene/search/SortField.java	(working copy)
@@ -128,6 +128,7 @@
    * according to the given locale.
    * @param field  Name of field to sort by, cannot be <code>null</code>.
    * @param locale Locale of values in the field.
+   * @see   LocaleBasedSortComparator
    */
   public SortField (String field, Locale locale) {
     this.field = field.intern();
@@ -139,6 +140,7 @@
    * according to the given locale.
    * @param field  Name of field to sort by, cannot be <code>null</code>.
    * @param locale Locale of values in the field.
+   * @see   LocaleBasedSortComparator
    */
   public SortField (String field, Locale locale, boolean reverse) {
     this.field = field.intern();
Index: src/java/org/apache/lucene/search/LocaleBasedSortComparator.java
===================================================================
--- src/java/org/apache/lucene/search/LocaleBasedSortComparator.java	(revision 0)
+++ src/java/org/apache/lucene/search/LocaleBasedSortComparator.java	(revision 0)
@@ -0,0 +1,83 @@
+/* $Id */
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.Collator;
+import java.util.Locale;
+
+/**
+ * <p>Linguistic sort based on locale.
+ * <p>This class builds a cache of collation keys (Comparable's) for a field.
+ * Comparing two collation keys is much faster than comparing two strings, as
+ * when using {@link SortField#SortField(String,Locale)}. The result is a
+ * <b>faster sort</b>, but also a <b>higher memory consumption</b>.
+ * <p>Example usage: <pre><code>
+ *   final SortComparatorSource frenchComparator = new LocaleBasedSortComparator(Locale.FRANCE);
+ *   final SortField french_asc = new SortField(&quot;fieldname&quot;, frenchComparator);
+ *   final SortField french_desc = new SortField(&quot;fieldname&quot;, frenchComparator, true);</code>
+ *   ...
+ *   Hits h = searcher.search(query, new Sort(french_asc));</code></pre>
+ * 
+ * @author  <a href="mailto:ronnie.kolehmainen@ub.uu.se">Ronnie Kolehmainen</a>
+ * @version $Date$, $Revision$
+ * @see     Collator#getCollationKey(String)
+ * @see     SortField#SortField(String,SortComparatorSource)
+ */
+public class LocaleBasedSortComparator extends SortComparator {
+  
+  private final Collator collator;
+  
+  /**
+   * Creates a new instance of LocaleBasedSortComparator
+   * @param  l the locale
+   */
+  public LocaleBasedSortComparator(Locale l) {
+    collator = Collator.getInstance(l);
+  }
+  
+  /**
+   * Returns an object which, when sorted according to natural order, will be
+   * ordered according to the collation rules defined by this collator.
+   * @param  termtext the text
+   * @return a {@link java.text.CollationKey collation key}
+   */
+  protected Comparable getComparable(String termtext) {
+    return collator.getCollationKey(termtext);
+  }
+  
+  /**
+   * Test for equality with another comparator.
+   * @param  o the other comparator
+   * @return see {@link Collator#equals(Object)}
+   */
+  public boolean equals(Object o) {
+    if (o instanceof LocaleBasedSortComparator) {
+      return collator.equals(((LocaleBasedSortComparator) o).collator);
+    }
+    return false;
+  }
+  
+  /**
+   * The hashcode.
+   * @return see {@link Collator#hashCode()}
+   */
+  public int hashCode() {
+    return collator.hashCode();
+  }
+}

Property changes on: src/java/org/apache/lucene/search/LocaleBasedSortComparator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Name: svn:eol-style
   + native

