You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2011/11/14 09:17:10 UTC
svn commit: r1201629 -
/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java
Author: shaie
Date: Mon Nov 14 08:17:10 2011
New Revision: 1201629
URL: http://svn.apache.org/viewvc?rev=1201629&view=rev
Log:
simplify CategoryListIteratorTest
Modified:
lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java
Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java?rev=1201629&r1=1201628&r2=1201629&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java Mon Nov 14 08:17:10 2011
@@ -13,6 +13,8 @@ import org.apache.lucene.analysis.tokena
import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Payload;
import org.apache.lucene.index.RandomIndexWriter;
@@ -139,8 +141,6 @@ public class CategoryListIteratorTest ex
Directory dir = newDirectory();
DataTokenStream dts = new DataTokenStream("1",new SortingIntEncoder(
new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder()))));
- DataTokenStream dts2 = new DataTokenStream("2",new SortingIntEncoder(
- new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder()))));
// this test requires that no payloads ever be randomly present!
final Analyzer noPayloadsAnalyzer = new Analyzer() {
@Override
@@ -152,36 +152,23 @@ public class CategoryListIteratorTest ex
RandomIndexWriter writer = new RandomIndexWriter(random, dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, noPayloadsAnalyzer).setMergePolicy(newLogMergePolicy()));
for (int i = 0; i < data.length; i++) {
- dts.setIdx(i);
Document doc = new Document();
- if (i==0 || i == 2) {
- doc.add(new Field("f", dts)); // only docs 0 & 2 have payloads!
+ if (i == 0) {
+ dts.setIdx(i);
+ doc.add(new Field("f", dts)); // only doc 0 has payloads!
+ } else {
+ doc.add(new Field("f", "1", Store.NO, Index.ANALYZED));
}
- dts2.setIdx(i);
- doc.add(new Field("f", dts2));
writer.addDocument(doc);
writer.commit();
}
- // add more documents to expose the bug.
- // for some reason, this bug is not exposed unless these additional documents are added.
- for (int i = 0; i < 10; ++i) {
- Document d = new Document();
- dts.setIdx(2);
- d.add(new Field("f", dts2));
- writer.addDocument(d);
- if (i %10 == 0) {
- writer.commit();
- }
-
- }
-
IndexReader reader = writer.getReader();
writer.close();
CategoryListIterator cli = new PayloadIntDecodingIterator(reader, new Term(
"f","1"), dts.encoder.createMatchingDecoder());
- cli.init();
+ assertTrue("Failed to initialize payload iterator", cli.init());
int totalCats = 0;
for (int i = 0; i < data.length; i++) {
// doc no. i
@@ -191,21 +178,19 @@ public class CategoryListIteratorTest ex
}
boolean hasDoc = cli.skipTo(i);
if (hasDoc) {
- assertTrue("Document "+i+" must not have a payload!", i==0 || i==2 );
+ assertTrue("Document " + i + " must not have a payload!", i == 0);
long cat;
while ((cat = cli.nextCategory()) < Integer.MAX_VALUE) {
assertTrue("expected category not found: " + cat, values.contains((int) cat));
++totalCats;
}
} else {
- assertFalse("Document "+i+" must have a payload!", i==0 || i==2 );
+ assertFalse("Document " + i + " must have a payload!", i == 0);
}
}
- assertEquals("Wrong number of total categories!", 4, totalCats);
+ assertEquals("Wrong number of total categories!", 2, totalCats);
- // Ok.. went through the first 4 docs, now lets try the 6th doc (docid 5)
- assertFalse("Doc #6 (docid=5) should not have a payload!",cli.skipTo(5));
reader.close();
dir.close();
}