lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ar...@apache.org
Subject svn commit: r1582473 - in /lucene/dev/trunk/lucene: CHANGES.txt suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java
Date Thu, 27 Mar 2014 21:00:40 GMT
Author: areek
Date: Thu Mar 27 21:00:40 2014
New Revision: 1582473

URL: http://svn.apache.org/r1582473
Log:
LUCENE-5555: Fix SortedInputIterator to correctly encode/decode contexts in presence of payload

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java
    lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1582473&r1=1582472&r2=1582473&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Mar 27 21:00:40 2014
@@ -210,6 +210,8 @@ Bug fixes
 
 * LUCENE-5111: Fix WordDelimiterFilter to return offsets in correct order.  (Robert Muir)
 
+* LUCENE-5555: Fix SortedInputIterator to correctly encode/decode contexts in presence of
payload (Areek Zillur)
+
 Test Framework
 
 * LUCENE-5449: Rename _TestUtil and _TestHelper to remove the leading _.

Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java?rev=1582473&r1=1582472&r2=1582473&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java
(original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java
Thu Mar 27 21:00:40 2014
@@ -209,7 +209,7 @@ public class SortedInputIterator impleme
     }
   }
   
-  /** encodes an entry (bytes+(payload)+(contexts)+weight) to the provided writer */
+  /** encodes an entry (bytes+(contexts)+(payload)+weight) to the provided writer */
   protected void encode(ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer,
BytesRef spare, BytesRef payload, Set<BytesRef> contexts, long weight) throws IOException
{
     int requiredLength = spare.length + 8 + ((hasPayloads) ? 2 + payload.length : 0);
     if (hasContexts) {
@@ -223,10 +223,6 @@ public class SortedInputIterator impleme
     }
     output.reset(buffer);
     output.writeBytes(spare.bytes, spare.offset, spare.length);
-    if (hasPayloads) {
-      output.writeBytes(payload.bytes, payload.offset, payload.length);
-      output.writeShort((short) payload.length);
-    }
     if (hasContexts) {
       for (BytesRef ctx : contexts) {
         output.writeBytes(ctx.bytes, ctx.offset, ctx.length);
@@ -234,6 +230,10 @@ public class SortedInputIterator impleme
       }
       output.writeShort((short) contexts.size());
     }
+    if (hasPayloads) {
+      output.writeBytes(payload.bytes, payload.offset, payload.length);
+      output.writeShort((short) payload.length);
+    }
     output.writeLong(weight);
     writer.write(buffer, 0, output.getPosition());
   }

Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java?rev=1582473&r1=1582472&r2=1582473&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java
(original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestInputIterator.java
Thu Mar 27 21:00:40 2014
@@ -48,9 +48,11 @@ public class TestInputIterator extends L
     TreeMap<BytesRef, SimpleEntry<Long, BytesRef>> sorted = new TreeMap<>(comparator);
     TreeMap<BytesRef, Long> sortedWithoutPayload = new TreeMap<>(comparator);
     TreeMap<BytesRef, SimpleEntry<Long, Set<BytesRef>>> sortedWithContext
= new TreeMap<>(comparator);
+    TreeMap<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>>
sortedWithPayloadAndContext = new TreeMap<>(comparator);
     Input[] unsorted = new Input[num];
     Input[] unsortedWithoutPayload = new Input[num];
     Input[] unsortedWithContexts = new Input[num];
+    Input[] unsortedWithPayloadAndContext = new Input[num];
     Set<BytesRef> ctxs;
     for (int i = 0; i < num; i++) {
       BytesRef key;
@@ -67,9 +69,11 @@ public class TestInputIterator extends L
       sortedWithoutPayload.put(key, value);
       sorted.put(key, new SimpleEntry<>(value, payload));
       sortedWithContext.put(key, new SimpleEntry<>(value, ctxs));
+      sortedWithPayloadAndContext.put(key, new SimpleEntry<>(value, new SimpleEntry<>(payload,
ctxs)));
       unsorted[i] = new Input(key, value, payload);
       unsortedWithoutPayload[i] = new Input(key, value);
       unsortedWithContexts[i] = new Input(key, value, ctxs);
+      unsortedWithPayloadAndContext[i] = new Input(key, value, payload, ctxs);
     }
     
     // test the sorted iterator wrapper with payloads
@@ -96,6 +100,20 @@ public class TestInputIterator extends L
     }
     assertNull(wrapper.next());
     
+    // test the sorted iterator wrapper with contexts and payload
+    wrapper = new SortedInputIterator(new InputArrayIterator(unsortedWithPayloadAndContext),
comparator);
+    Iterator<Map.Entry<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>>>
expectedPayloadContextEntries = sortedWithPayloadAndContext.entrySet().iterator();
+    while (expectedPayloadContextEntries.hasNext()) {
+      Map.Entry<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>>
entry = expectedPayloadContextEntries.next();
+      assertEquals(entry.getKey(), wrapper.next());
+      assertEquals(entry.getValue().getKey().longValue(), wrapper.weight());
+      Set<BytesRef> actualCtxs = entry.getValue().getValue().getValue();
+      assertEquals(actualCtxs, wrapper.contexts());
+      BytesRef actualPayload = entry.getValue().getValue().getKey();
+      assertEquals(actualPayload, wrapper.payload());
+    }
+    assertNull(wrapper.next());
+    
     // test the unsorted iterator wrapper with payloads
     wrapper = new UnsortedInputIterator(new InputArrayIterator(unsorted));
     TreeMap<BytesRef, SimpleEntry<Long, BytesRef>> actual = new TreeMap<>();



Mime
View raw message