lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r620765 - in /lucene/java/branches/lucene_2_3: CHANGES.txt src/java/org/apache/lucene/analysis/CharArraySet.java src/test/org/apache/lucene/analysis/TestCharArraySet.java
Date Tue, 12 Feb 2008 11:24:23 GMT
Author: mikemccand
Date: Tue Feb 12 03:24:14 2008
New Revision: 620765

URL: http://svn.apache.org/viewvc?rev=620765&view=rev
Log:
LUCENE-1163 (backport to 2.3): fixed bug in CharArraySet.contains that was ignoring the 'offset'
argument

Modified:
    lucene/java/branches/lucene_2_3/CHANGES.txt
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java
    lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java

Modified: lucene/java/branches/lucene_2_3/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/CHANGES.txt?rev=620765&r1=620764&r2=620765&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_3/CHANGES.txt Tue Feb 12 03:24:14 2008
@@ -10,12 +10,16 @@
  1. LUCENE-1168: Fixed corruption cases when autoCommit=false and
     documents have mixed term vectors (Suresh Guvvala via Mike
     McCandless).
-	
+
  2. LUCENE-1171: Fixed some cases where OOM errors could cause
     deadlock in IndexWriter (Mike McCandless).
 
  3. LUCENE-1173: Fixed corruption case when autoCommit=false and bulk
     merging of stored fields is used (Yonik via Mike McCandless).
+
+ 4. LUCENE-1163: Fixed bug in CharArraySet.contains(char[] buffer, int
+    offset, int len) that was ignoring offset and thus giving the
+    wrong answer.  (Thomas Peuss via Mike McCandless)
 	
 New features
 

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java?rev=620765&r1=620764&r2=620765&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java
(original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java
Tue Feb 12 03:24:14 2008
@@ -66,7 +66,7 @@
   }
 
   private int getSlot(char[] text, int off, int len) {
-    int code = getHashCode(text, len);
+    int code = getHashCode(text, off, len);
     int pos = code & (entries.length-1);
     char[] text2 = entries[pos];
     if (text2 != null && !equals(text, off, len, text2)) {
@@ -175,14 +175,15 @@
     }
   }
   
-  private int getHashCode(char[] text, int len) {
+  private int getHashCode(char[] text, int offset, int len) {
     int code = 0;
+    final int stop = offset + len;
     if (ignoreCase) {
-      for (int i=0; i<len; i++) {
+      for (int i=offset; i<stop; i++) {
         code = code*31 + Character.toLowerCase(text[i]);
       }
     } else {
-      for (int i=0; i<len; i++) {
+      for (int i=offset; i<stop; i++) {
         code = code*31 + text[i];
       }
     }

Modified: lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java?rev=620765&r1=620764&r2=620765&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java
(original)
+++ lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java
Tue Feb 12 03:24:14 2008
@@ -17,20 +17,27 @@
  * limitations under the License.
  */
 
-import java.io.IOException;
+import java.util.Arrays;
 
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.analysis.StopAnalyzer;
-import org.apache.lucene.analysis.CharArraySet;
 
 public class TestCharArraySet extends LuceneTestCase
 {
-    public void testRehash() throws Exception {
-      CharArraySet cas = new CharArraySet(0, true);
-      for(int i=0;i<StopAnalyzer.ENGLISH_STOP_WORDS.length;i++)
-        cas.add(StopAnalyzer.ENGLISH_STOP_WORDS[i]);
-      assertEquals(StopAnalyzer.ENGLISH_STOP_WORDS.length, cas.size());
-      for(int i=0;i<StopAnalyzer.ENGLISH_STOP_WORDS.length;i++)
-        assertTrue(cas.contains(StopAnalyzer.ENGLISH_STOP_WORDS[i]));
-    }
+  public void testRehash() throws Exception {
+    CharArraySet cas = new CharArraySet(0, true);
+    for(int i=0;i<StopAnalyzer.ENGLISH_STOP_WORDS.length;i++)
+      cas.add(StopAnalyzer.ENGLISH_STOP_WORDS[i]);
+    assertEquals(StopAnalyzer.ENGLISH_STOP_WORDS.length, cas.size());
+    for(int i=0;i<StopAnalyzer.ENGLISH_STOP_WORDS.length;i++)
+      assertTrue(cas.contains(StopAnalyzer.ENGLISH_STOP_WORDS[i]));
+  }
+
+  public void testNonZeroOffset() {
+    String[] words={"Hello","World","this","is","a","test"};
+    char[] findme="xthisy".toCharArray();   
+    CharArraySet set=new CharArraySet(10,true);
+    set.addAll(Arrays.asList(words));
+    assertTrue(set.contains(findme, 1, 4));
+    assertTrue(set.contains(new String(findme,1,4)));
+  }
 }



Mime
View raw message