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 2014/01/29 15:53:04 UTC
svn commit: r1562467 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/facet/
lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
Author: shaie
Date: Wed Jan 29 14:53:03 2014
New Revision: 1562467
URL: http://svn.apache.org/r1562467
Log:
LUCENE-5367: add test to ensure we don't introduce the bug again
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/facet/ (props changed)
lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java?rev=1562467&r1=1562466&r2=1562467&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java Wed Jan 29 14:53:03 2014
@@ -19,9 +19,20 @@ package org.apache.lucene.facet;
import java.util.Arrays;
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
+import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util._TestUtil;
public class TestFacetsConfig extends FacetTestCase {
+
public void testPathToStringAndBack() throws Exception {
int iters = atLeast(1000);
for(int i=0;i<iters;i++) {
@@ -43,4 +54,35 @@ public class TestFacetsConfig extends Fa
assertTrue(Arrays.equals(parts, parts2));
}
}
+
+ public void testAddSameDocTwice() throws Exception {
+ // LUCENE-5367: this was a problem with the previous code, making sure it
+ // works with the new code.
+ Directory indexDir = newDirectory(), taxoDir = newDirectory();
+ IndexWriter indexWriter = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+ DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
+ FacetsConfig facetsConfig = new FacetsConfig();
+ Document doc = new Document();
+ doc.add(new FacetField("a", "b"));
+ doc = facetsConfig.build(taxoWriter, doc);
+ // these two addDocument() used to fail
+ indexWriter.addDocument(doc);
+ indexWriter.addDocument(doc);
+ IOUtils.close(indexWriter, taxoWriter);
+
+ DirectoryReader indexReader = DirectoryReader.open(indexDir);
+ DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+ IndexSearcher searcher = newSearcher(indexReader);
+ FacetsCollector fc = new FacetsCollector();
+ searcher.search(new MatchAllDocsQuery(), fc);
+
+ Facets facets = getTaxonomyFacetCounts(taxoReader, facetsConfig, fc);
+ FacetResult res = facets.getTopChildren(10, "a");
+ assertEquals(1, res.labelValues.length);
+ assertEquals(2, res.labelValues[0].value);
+ IOUtils.close(indexReader, taxoReader);
+
+ IOUtils.close(indexDir, taxoDir);
+ }
+
}