lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r618652 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/analysis/CharArraySet.java src/test/org/apache/lucene/analysis/TestCharArraySet.java
Date Tue, 05 Feb 2008 14:02:33 GMT
Author: mikemccand
Date: Tue Feb  5 06:02:32 2008
New Revision: 618652

URL: http://svn.apache.org/viewvc?rev=618652&view=rev
Log:
LUCENE-1163: get CharArraySet.contains(char[], int offset, int length) to actually pay attention
to offset

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

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=618652&r1=618651&r2=618652&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Feb  5 06:02:32 2008
@@ -40,6 +40,10 @@
     
  1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimze a single 
     clause query if minNumShouldMatch<=0. (Shai Erera via Michael Busch)
+
+ 2. 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/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java?rev=618652&r1=618651&r2=618652&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java Tue Feb  5 06:02:32
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/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java?rev=618652&r1=618651&r2=618652&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java Tue Feb  5
06:02:32 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