Apache Lucene open-source search software
LUCENE-1643: use reusable RawCollationKey for better performance
Michael McCandless2dd7d33e86d6
diff --git a/contrib/CHANGES.txt b/contrib/CHANGES.txtindex 4e0cd4970d0..178f587f025 100644--- a/contrib/CHANGES.txt+++ b/contrib/CHANGES.txt@@ -61,6 +61,11 @@ New featuresModel to tokenize Chinese words in a more intelligent way.(Xiaoping Gao via Mike McCandless)+Optimizations++ 1. LUCENE-1643: Re-use the collation key (RawCollationKey) for+ better performance, in ICUCollationKeyFilter. (Robert Muir via+ Mike McCandless)Documentationdiff --git a/contrib/collation/src/java/org/apache/lucene/collation/ICUCollationKeyFilter.java b/contrib/collation/src/java/org/apache/lucene/collation/ICUCollationKeyFilter.javaindex aadcb4b1252..596decd325f 100644--- a/contrib/collation/src/java/org/apache/lucene/collation/ICUCollationKeyFilter.java+++ b/contrib/collation/src/java/org/apache/lucene/collation/ICUCollationKeyFilter.java@@ -19,6 +19,8 @@ package org.apache.lucene.collation;import com.ibm.icu.text.Collator;+import com.ibm.icu.text.RawCollationKey;+import org.apache.lucene.analysis.TokenFilter;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.Token;@@ -61,6 +63,7 @@ import java.nio.CharBuffer;*/public class ICUCollationKeyFilter extends TokenFilter {private Collator collator = null;+ private RawCollationKey reusableKey = new RawCollationKey();/***@@ -78,8 +81,8 @@ public class ICUCollationKeyFilter extends TokenFilter {if (nextToken != null) {char[] termBuffer = nextToken.termBuffer();String termText = new String(termBuffer, 0, nextToken.termLength());- byte[] collationKey = collator.getCollationKey(termText).toByteArray();- ByteBuffer collationKeyBuf = ByteBuffer.wrap(collationKey);+ collator.getRawCollationKey(termText, reusableKey);+ ByteBuffer collationKeyBuf = ByteBuffer.wrap(reusableKey.bytes, 0, reusableKey.size);int encodedLength= IndexableBinaryStringTools.getEncodedLength(collationKeyBuf);if (encodedLength > termBuffer.length) {