lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1543506 - in /lucene/dev/branches/lucene5339/lucene/facet/src: java/org/apache/lucene/facet/simple/ test/org/apache/lucene/facet/ test/org/apache/lucene/facet/simple/
Date Tue, 19 Nov 2013 17:13:14 GMT
Author: mikemccand
Date: Tue Nov 19 17:13:14 2013
New Revision: 1543506

URL: http://svn.apache.org/r1543506
Log:
LUCENE-5339: migrate some more tests; fix 'ignores IntsRef.offset bug' in TaxoFacetCounts;
add FacetTestCase.getFacetCounts

Modified:
    lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/FacetIndexWriter.java
    lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetCounts.java
    lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetSumValueSource.java
    lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/FacetTestCase.java
    lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/simple/TestTaxonomyFacetCounts.java

Modified: lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/FacetIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/FacetIndexWriter.java?rev=1543506&r1=1543505&r2=1543506&view=diff
==============================================================================
--- lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/FacetIndexWriter.java
(original)
+++ lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/FacetIndexWriter.java
Tue Nov 19 17:13:14 2013
@@ -248,6 +248,7 @@ public class FacetIndexWriter extends In
     }
   }
 
+  // nocommit open this up
   /** We can open this up if/when we really need
    *  pluggability on the encoding. */
   private final BytesRef dedupAndEncode(IntsRef ordinals) {

Modified: lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetCounts.java?rev=1543506&r1=1543505&r2=1543506&view=diff
==============================================================================
--- lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetCounts.java
(original)
+++ lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetCounts.java
Tue Nov 19 17:13:14 2013
@@ -60,7 +60,7 @@ public class TaxonomyFacetCounts extends
       while (doc < length && (doc = bits.nextSetBit(doc)) != -1) {
         ords.get(doc, scratch);
         for(int i=0;i<scratch.length;i++) {
-          ++counts[scratch.ints[i]];
+          counts[scratch.ints[scratch.offset+i]]++;
         }
         ++doc;
       }

Modified: lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetSumValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetSumValueSource.java?rev=1543506&r1=1543505&r2=1543506&view=diff
==============================================================================
--- lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetSumValueSource.java
(original)
+++ lucene/dev/branches/lucene5339/lucene/facet/src/java/org/apache/lucene/facet/simple/TaxonomyFacetSumValueSource.java
Tue Nov 19 17:13:14 2013
@@ -40,17 +40,23 @@ import org.apache.lucene.util.IntsRef;
 /** Aggregates sum of values from a {@link ValueSource}, for
  *  each facet label. */
 
-// nocommit jdoc that this assumes/requires the default encoding
-
 public class TaxonomyFacetSumValueSource extends TaxonomyFacets {
   private final float[] values;
   private final OrdinalsReader ordinalsReader;
 
+  /** Aggreggates float facet values from the provided
+   *  {@link ValueSource}, pulling ordinals using {@link
+   *  DocValuesOrdinalsReader} against the default indexed
+   *  facet field {@link
+   *  FacetsConfig#DEFAULT_INDEX_FIELD_NAME}. */
   public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config,
                                      SimpleFacetsCollector fc, ValueSource valueSource) throws
IOException {
     this(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME), taxoReader,
config, fc, valueSource);
   }
 
+  /** Aggreggates float facet values from the provided
+   *  {@link ValueSource}, and pulls ordinals from the
+   *  provided {@link OrdinalsReader}. */
   public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader,
                                      FacetsConfig config, SimpleFacetsCollector fc, ValueSource
valueSource) throws IOException {
     super(ordinalsReader.getIndexFieldName(), taxoReader, config);

Modified: lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/FacetTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/FacetTestCase.java?rev=1543506&r1=1543505&r2=1543506&view=diff
==============================================================================
--- lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/FacetTestCase.java
(original)
+++ lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/FacetTestCase.java
Tue Nov 19 17:13:14 2013
@@ -1,5 +1,6 @@
 package org.apache.lucene.facet;
 
+import java.io.IOException;
 import java.util.Random;
 
 import org.apache.lucene.facet.encoding.DGapIntEncoder;
@@ -12,6 +13,15 @@ import org.apache.lucene.facet.encoding.
 import org.apache.lucene.facet.encoding.UniqueValuesIntEncoder;
 import org.apache.lucene.facet.encoding.VInt8IntEncoder;
 import org.apache.lucene.facet.params.CategoryListParams;
+import org.apache.lucene.facet.simple.CachedOrdinalsReader;
+import org.apache.lucene.facet.simple.DocValuesOrdinalsReader;
+import org.apache.lucene.facet.simple.Facets;
+import org.apache.lucene.facet.simple.FacetsConfig;
+import org.apache.lucene.facet.simple.FastTaxonomyFacetCounts;
+import org.apache.lucene.facet.simple.OrdinalsReader;
+import org.apache.lucene.facet.simple.SimpleFacetsCollector;
+import org.apache.lucene.facet.simple.TaxonomyFacetCounts;
+import org.apache.lucene.facet.taxonomy.TaxonomyReader;
 import org.apache.lucene.util.LuceneTestCase;
 
 /*
@@ -60,5 +70,19 @@ public abstract class FacetTestCase exte
       }
     };
   }
-  
+
+  public Facets getFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, SimpleFacetsCollector
c) throws IOException {
+    Facets facets;
+    if (random().nextBoolean()) {
+      facets = new FastTaxonomyFacetCounts(taxoReader, config, c);
+    } else {
+      OrdinalsReader ordsReader = new DocValuesOrdinalsReader();
+      if (random().nextBoolean()) {
+        ordsReader = new CachedOrdinalsReader(ordsReader);
+      }
+      facets = new TaxonomyFacetCounts(ordsReader, taxoReader, config, c);
+    }
+
+    return facets;
+  }
 }

Modified: lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/simple/TestTaxonomyFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/simple/TestTaxonomyFacetCounts.java?rev=1543506&r1=1543505&r2=1543506&view=diff
==============================================================================
--- lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/simple/TestTaxonomyFacetCounts.java
(original)
+++ lucene/dev/branches/lucene5339/lucene/facet/src/test/org/apache/lucene/facet/simple/TestTaxonomyFacetCounts.java
Tue Nov 19 17:13:14 2013
@@ -183,16 +183,7 @@ public class TestTaxonomyFacetCounts ext
     SimpleFacetsCollector c = new SimpleFacetsCollector();
     searcher.search(new MatchAllDocsQuery(), c);    
 
-    Facets facets;
-    if (random().nextBoolean()) {
-      facets = new FastTaxonomyFacetCounts(taxoReader, new FacetsConfig(), c);
-    } else {
-      OrdinalsReader ordsReader = new DocValuesOrdinalsReader();
-      if (random().nextBoolean()) {
-        ordsReader = new CachedOrdinalsReader(ordsReader);
-      }
-      facets = new TaxonomyFacetCounts(ordsReader, taxoReader, new FacetsConfig(), c);
-    }
+    Facets facets = getFacetCounts(taxoReader, new FacetsConfig(), c);
 
     // Ask for top 10 labels for any dims that have counts:
     List<SimpleFacetResult> results = facets.getAllDims(10);
@@ -275,7 +266,6 @@ public class TestTaxonomyFacetCounts ext
   // nocommit in the sparse case test that we are really
   // sorting by the correct dim count
 
-  /*
   public void testReallyNoNormsForDrillDown() throws Exception {
     Directory dir = newDirectory();
     Directory taxoDir = newDirectory();
@@ -289,13 +279,12 @@ public class TestTaxonomyFacetCounts ext
           return sim;
         }
       });
-    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
-    FacetFields facetFields = new FacetFields(taxoWriter);      
+    IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, new FacetsConfig());
 
     Document doc = new Document();
     doc.add(newTextField("field", "text", Field.Store.NO));
-    facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
+    doc.add(new FacetField("a", "path"));
     writer.addDocument(doc);
     writer.close();
     taxoWriter.close();
@@ -303,54 +292,42 @@ public class TestTaxonomyFacetCounts ext
     taxoDir.close();
   }
 
-  public void testAllParents() throws Exception {
+  public void testMultiValuedHierarchy() throws Exception {
     Directory dir = newDirectory();
     Directory taxoDir = newDirectory();
-    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
     DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
-
-    CategoryListParams clp = new CategoryListParams("$facets") {
-        @Override
-        public OrdinalPolicy getOrdinalPolicy(String fieldName) {
-          return OrdinalPolicy.ALL_PARENTS;
-        }
-      };
-    FacetIndexingParams fip = new FacetIndexingParams(clp);
-
-    FacetFields facetFields = new FacetFields(taxoWriter, fip);
+    IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
+    FacetsConfig config = new FacetsConfig();
+    config.setHierarchical("a");
+    config.setMultiValued("a");
+    IndexWriter writer = new FacetIndexWriter(dir, iwc, taxoWriter, config);
 
     Document doc = new Document();
     doc.add(newTextField("field", "text", Field.Store.NO));
-    facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
+    doc.add(new FacetField("a", "path", "x"));
+    doc.add(new FacetField("a", "path", "y"));
     writer.addDocument(doc);
 
     // NRT open
-    IndexSearcher searcher = newSearcher(writer.getReader());
+    IndexSearcher searcher = newSearcher(DirectoryReader.open(writer, true));
     writer.close();
 
     // NRT open
     TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
     taxoWriter.close();
     
-    FacetSearchParams fsp = new FacetSearchParams(fip,
-                                                  new CountFacetRequest(new CategoryPath("a",
'/'), 10));
-
     // Aggregate the facet counts:
-    FacetsCollector c = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);
+    SimpleFacetsCollector c = new SimpleFacetsCollector();
 
     // MatchAllDocsQuery is for "browsing" (counts facets
     // for all non-deleted docs in the index); normally
     // you'd use a "normal" query, and use MultiCollector to
     // wrap collecting the "normal" hits and also facets:
     searcher.search(new MatchAllDocsQuery(), c);
-    List<FacetResult> results = c.getFacetResults();
-    assertEquals(1, results.size());
-    assertEquals(1, (int) results.get(0).getFacetResultNode().value);
-
-    // LUCENE-4913:
-    for(FacetResultNode childNode : results.get(0).getFacetResultNode().subResults) {
-      assertTrue(childNode.ordinal != 0);
-    }
+    Facets facets = getFacetCounts(taxoReader, config, c);
+    SimpleFacetResult result = facets.getTopChildren(10, "a");
+    assertEquals(1, result.labelValues.length);
+    assertEquals(1, result.labelValues[0].value.intValue());
 
     searcher.getIndexReader().close();
     taxoReader.close();
@@ -358,6 +335,7 @@ public class TestTaxonomyFacetCounts ext
     taxoDir.close();
   }
 
+  /*
   public void testLabelWithDelimiter() throws Exception {
     Directory dir = newDirectory();
     Directory taxoDir = newDirectory();



Mime
View raw message