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 2012/12/10 16:32:11 UTC
svn commit: r1419524 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/facet/
lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/
lucene/facet/src/java/org/apache/lucene/facet/index/params/
lucene/facet/src/test/org/apache/lucene/f...
Author: shaie
Date: Mon Dec 10 15:32:07 2012
New Revision: 1419524
URL: http://svn.apache.org/viewvc?rev=1419524&view=rev
Log:
LUCENE-4604: Implement OrdinalPolicy.NO_PARENTS
Removed:
lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultOrdinalPolicy.java
lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultPathPolicy.java
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/lucene/facet/ (props changed)
lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java
lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java
lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java
lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java
lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java
lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java
Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Mon Dec 10 15:32:07 2012
@@ -59,7 +59,13 @@ Changes in backwards compatibility polic
re-index is not done, then an indexed point is ~1/2 the smallest grid cell
larger and as such is slightly more likely to match a query shape.
(David Smiley)
-
+
+* LUCENE-4604: DefaultOrdinalPolicy removed in favor of OrdinalPolicy.ALL_PARENTS.
+ Same for DefaultPathPolicy (now PathPolicy.ALL_CATEGORIES). In addition, you
+ can use OrdinalPolicy.NO_PARENTS to never write any parent category ordinal
+ to the fulltree posting payload (but note that you need a special
+ FacetsAccumulator - see javadocs). (Shai Erera)
+
New Features
* LUCENE-4226: New experimental StoredFieldsFormat that compresses chunks of
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java Mon Dec 10 15:32:07 2012
@@ -3,6 +3,8 @@ package org.apache.lucene.facet.index.ca
import java.io.Serializable;
import org.apache.lucene.facet.index.streaming.CategoryParentsStream;
+import org.apache.lucene.facet.search.FacetsAccumulator;
+import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
/*
@@ -27,13 +29,41 @@ import org.apache.lucene.facet.taxonomy.
* category ordinal is added to the stream, and than its parents are being added
* one after the other using {@link TaxonomyWriter#getParent(int)}. <br>
* That loop should have a stop point - the default approach (excluding the
- * ROOT) is implemented in {@link DefaultOrdinalPolicy}.
+ * ROOT) is implemented in {@link OrdinalPolicy#ALL_PARENTS}.
*
* @lucene.experimental
*/
public interface OrdinalPolicy extends Serializable {
/**
+ * An {@link OrdinalPolicy} which never stores parent ordinals. Useful if you
+ * only want to store the exact categories that were added to the document.
+ * Note that this is a rather expert policy, which requires a matching
+ * {@link FacetsAccumulator} that computes the weight of the parent categories
+ * on-the-fly.
+ */
+ public static final OrdinalPolicy NO_PARENTS = new OrdinalPolicy() {
+ @Override
+ public boolean shouldAdd(int ordinal) { return false; }
+
+ @Override
+ public void init(TaxonomyWriter taxonomyWriter) {}
+ };
+
+ /**
+ * An {@link OrdinalPolicy} which stores all parent ordinals, except
+ * {@link TaxonomyReader#ROOT_ORDINAL}. This is the default
+ * {@link OrdinalPolicy} and works with the default {@link FacetsAccumulator}.
+ */
+ public static final OrdinalPolicy ALL_PARENTS = new OrdinalPolicy() {
+ @Override
+ public boolean shouldAdd(int ordinal) { return ordinal > TaxonomyReader.ROOT_ORDINAL; }
+
+ @Override
+ public void init(TaxonomyWriter taxonomyWriter) {}
+ };
+
+ /**
* Check whether a given category ordinal should be added to the stream.
*
* @param ordinal
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java Mon Dec 10 15:32:07 2012
@@ -23,17 +23,25 @@ import org.apache.lucene.facet.taxonomy.
*/
/**
- * Filtering category paths in {@link CategoryParentsStream}, where a given
- * category is added to the stream, and than all its parents are being
- * added one after the other by successively removing the last component. <br>
- * That loop should have a stop point - the default approach (excluding the
- * ROOT) is implemented in {@link DefaultOrdinalPolicy}.
+ * Determines which {@link CategoryPath categories} should be added as terms to
+ * the {@link CategoryParentsStream}. The default approach is implemented by
+ * {@link #ALL_CATEGORIES}.
*
* @lucene.experimental
*/
public interface PathPolicy extends Serializable {
/**
+ * A {@link PathPolicy} which adds all {@link CategoryPath} that have at least
+ * one component (i.e. {@link CategoryPath#length()} > 0) to the categories
+ * stream.
+ */
+ public static final PathPolicy ALL_CATEGORIES = new PathPolicy() {
+ @Override
+ public boolean shouldAdd(CategoryPath categoryPath) { return categoryPath.length() > 0; }
+ };
+
+ /**
* Check whether a given category path should be added to the stream.
*
* @param categoryPath
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java Mon Dec 10 15:32:07 2012
@@ -3,8 +3,6 @@ package org.apache.lucene.facet.index.pa
import java.util.ArrayList;
import java.util.List;
-import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy;
-import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy;
import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
import org.apache.lucene.facet.taxonomy.CategoryPath;
@@ -82,7 +80,7 @@ public class DefaultFacetIndexingParams
* @see #getOrdinalPolicy()
*/
protected OrdinalPolicy fixedOrdinalPolicy() {
- return new DefaultOrdinalPolicy();
+ return OrdinalPolicy.ALL_PARENTS;
}
/**
@@ -90,7 +88,7 @@ public class DefaultFacetIndexingParams
* @see #getPathPolicy()
*/
protected PathPolicy fixedPathPolicy() {
- return new DefaultPathPolicy();
+ return PathPolicy.ALL_CATEGORIES;
}
public final int getPartitionSize() {
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java Mon Dec 10 15:32:07 2012
@@ -1,16 +1,12 @@
package org.apache.lucene.facet.index.categorypolicy;
-import org.apache.lucene.store.Directory;
-import org.junit.Test;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy;
-import org.apache.lucene.facet.index.categorypolicy.NonTopLevelOrdinalPolicy;
-import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -34,7 +30,7 @@ public class OrdinalPolicyTest extends L
@Test
public void testDefaultOrdinalPolicy() {
// check ordinal policy
- OrdinalPolicy ordinalPolicy = new DefaultOrdinalPolicy();
+ OrdinalPolicy ordinalPolicy = OrdinalPolicy.ALL_PARENTS;
assertFalse("default ordinal policy should not match root", ordinalPolicy
.shouldAdd(TaxonomyReader.ROOT_ORDINAL));
for (int i = 0; i < 300; i++) {
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java Mon Dec 10 15:32:07 2012
@@ -1,15 +1,11 @@
package org.apache.lucene.facet.index.categorypolicy;
-import org.apache.lucene.store.Directory;
-import org.junit.Test;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy;
-import org.apache.lucene.facet.index.categorypolicy.NonTopLevelPathPolicy;
-import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -34,7 +30,7 @@ public class PathPolicyTest extends Luce
public void testDefaultPathPolicy() {
// check path policy
CategoryPath cp = new CategoryPath();
- PathPolicy pathPolicy = new DefaultPathPolicy();
+ PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES;
assertFalse("default path policy should not accept root",
pathPolicy.shouldAdd(cp));
for (int i = 0; i < 300; i++) {
Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java?rev=1419524&r1=1419523&r2=1419524&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java Mon Dec 10 15:32:07 2012
@@ -1,20 +1,14 @@
package org.apache.lucene.facet.index.params;
-import org.apache.lucene.index.Term;
-import org.junit.Test;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy;
-import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy;
import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
-import org.apache.lucene.facet.index.params.CategoryListParams;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
-import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.search.DrillDown;
import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.util.PartitionsUtils;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -84,13 +78,10 @@ public class DefaultFacetIndexingParamsT
@Test
public void testCategoryPolicies() {
FacetIndexingParams dfip = new DefaultFacetIndexingParams();
- long seed = System.currentTimeMillis();
// check path policy
CategoryPath cp = new CategoryPath();
- PathPolicy pathPolicy = new DefaultPathPolicy();
- assertEquals("path policy does not match default for root" + "(seed "
- + seed + ")", pathPolicy.shouldAdd(cp), dfip.getPathPolicy()
- .shouldAdd(cp));
+ PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES;
+ assertEquals("path policy does not match default for root", pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp));
for (int i = 0; i < 30; i++) {
int nComponents = random().nextInt(10);
String[] components = new String[nComponents];
@@ -98,21 +89,19 @@ public class DefaultFacetIndexingParamsT
components[j] = (Integer.valueOf(random().nextInt(30))).toString();
}
cp = new CategoryPath(components);
- assertEquals("path policy does not match default for "
- + cp.toString('/') + "(seed " + seed + ")", pathPolicy
- .shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp));
+ assertEquals("path policy does not match default for " + cp.toString('/'),
+ pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp));
}
// check ordinal policy
- OrdinalPolicy ordinalPolicy = new DefaultOrdinalPolicy();
- assertEquals("ordinal policy does not match default for root"
- + "(seed " + seed + ")", ordinalPolicy
- .shouldAdd(TaxonomyReader.ROOT_ORDINAL), dfip
- .getOrdinalPolicy().shouldAdd(TaxonomyReader.ROOT_ORDINAL));
+ OrdinalPolicy ordinalPolicy = OrdinalPolicy.ALL_PARENTS;
+ assertEquals("ordinal policy does not match default for root",
+ ordinalPolicy.shouldAdd(TaxonomyReader.ROOT_ORDINAL),
+ dfip.getOrdinalPolicy().shouldAdd(TaxonomyReader.ROOT_ORDINAL));
for (int i = 0; i < 30; i++) {
int ordinal = random().nextInt();
- assertEquals("ordinal policy does not match default for " + ordinal
- + "(seed " + seed + ")", ordinalPolicy.shouldAdd(ordinal),
+ assertEquals("ordinal policy does not match default for " + ordinal,
+ ordinalPolicy.shouldAdd(ordinal),
dfip.getOrdinalPolicy().shouldAdd(ordinal));
}
}