You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/02/13 18:44:02 UTC
svn commit: r1659626 - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/spatial/ lucene/spatial/src/java/org/apache/lucene/spatial/
lucene/spatial/src/java/org/apache/lucene/spatial/prefix/
lucene/spatial/src/java/org/apache/lucene/spatial/prefix/t...
Author: dsmiley
Date: Fri Feb 13 17:44:01 2015
New Revision: 1659626
URL: http://svn.apache.org/r1659626
Log:
LUCENE-6215: Move NumberRangePrefixTreeStrategy into correct package
Added:
lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java
- copied, changed from r1659615, lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java
Removed:
lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/NumberRangePrefixTreeStrategy.java
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/spatial/ (props changed)
lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/DateRangeField.java
Copied: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java (from r1659615, lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java?p2=lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java&p1=lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java&r1=1659615&r2=1659626&rev=1659626&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/NumberRangePrefixTreeStrategy.java Fri Feb 13 17:44:01 2015
@@ -17,24 +17,13 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Shape;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.spatial.prefix.tree.Cell;
import org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree;
-import static org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape;
-
/** A PrefixTree based on Number/Date ranges. This isn't very "spatial" on the surface (to the user) but
* it's implemented using spatial so that's why it's here extending a SpatialStrategy. When using this class, you will
* use various utility methods on the prefix tree implementation to convert objects/strings to/from shapes.
@@ -71,133 +60,4 @@ public class NumberRangePrefixTreeStrate
public ValueSource makeDistanceValueSource(Point queryPoint, double multiplier) {
throw new UnsupportedOperationException();
}
-
- /** Calculates facets between {@code start} and {@code end} to a detail level one greater than that provided by the
- * arguments. For example providing March to October of 2014 would return facets to the day level of those months.
- * This is just a convenience method.
- * @see #calcFacets(IndexReaderContext, Filter, Shape, int)
- */
- public Facets calcFacets(IndexReaderContext context, Filter filter, UnitNRShape start, UnitNRShape end)
- throws IOException {
- Shape facetRange = getGrid().toRangeShape(start, end);
- int detailLevel = Math.max(start.getLevel(), end.getLevel()) + 1;
- return calcFacets(context, filter, facetRange, detailLevel);
- }
-
- /**
- * Calculates facets (aggregated counts) given a range shape (start-end span) and a level, which specifies the detail.
- * To get the level of an existing shape, say a Calendar, call
- * {@link org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree#toUnitShape(Object)} then call
- * {@link org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape#getLevel()}.
- * Facet computation is implemented by navigating the underlying indexed terms efficiently.
- */
- public Facets calcFacets(IndexReaderContext context, Filter filter, Shape facetRange, final int level)
- throws IOException {
- final Facets facets = new Facets(level);
- PrefixTreeFacetCounter.compute(this, context, filter, facetRange, level,
- new PrefixTreeFacetCounter.FacetVisitor() {
- Facets.FacetParentVal parentFacet;
- UnitNRShape parentShape;
-
- @Override
- public void visit(Cell cell, int count) {
- if (cell.getLevel() < level - 1) {//some ancestor of parent facet level, direct or distant
- parentFacet = null;//reset
- parentShape = null;//reset
- facets.topLeaves += count;
- } else if (cell.getLevel() == level - 1) {//parent
- //set up FacetParentVal
- setupParent((UnitNRShape) cell.getShape());
- parentFacet.parentLeaves += count;
- } else {//at facet level
- UnitNRShape unitShape = (UnitNRShape) cell.getShape();
- UnitNRShape unitShapeParent = unitShape.getShapeAtLevel(unitShape.getLevel() - 1);
- if (parentFacet == null || !parentShape.equals(unitShapeParent)) {
- setupParent(unitShapeParent);
- }
- //lazy init childCounts
- if (parentFacet.childCounts == null) {
- parentFacet.childCounts = new int[parentFacet.childCountsLen];
- }
- parentFacet.childCounts[unitShape.getValAtLevel(cell.getLevel())] += count;
- }
- }
-
- private void setupParent(UnitNRShape unitShape) {
- parentShape = unitShape.clone();
- //Look for existing parentFacet (from previous segment), or create anew if needed
- parentFacet = facets.parents.get(parentShape);
- if (parentFacet == null) {//didn't find one; make a new one
- parentFacet = new Facets.FacetParentVal();
- parentFacet.childCountsLen = getGrid().getNumSubCells(parentShape);
- facets.parents.put(parentShape, parentFacet);
- }
- }
- });
- return facets;
- }
-
- /** Facet response information */
- public static class Facets {
- //TODO consider a variable-level structure -- more general purpose.
-
- public Facets(int detailLevel) {
- this.detailLevel = detailLevel;
- }
-
- /** The bottom-most detail-level counted, as requested. */
- public final int detailLevel;
-
- /**
- * The count of documents with ranges that completely spanned the parents of the detail level. In more technical
- * terms, this is the count of leaf cells 2 up and higher from the bottom. Usually you only care about counts at
- * detailLevel, and so you will add this number to all other counts below, including to omitted/implied children
- * counts of 0. If there are no indexed ranges (just instances, i.e. fully specified dates) then this value will
- * always be 0.
- */
- public int topLeaves;
-
- /** Holds all the {@link FacetParentVal} instances in order of the key. This is sparse; there won't be an
- * instance if it's count and children are all 0. The keys are {@link org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape} shapes, which can be
- * converted back to the original Object (i.e. a Calendar) via
- * {@link NumberRangePrefixTree#toObject(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)}. */
- public final SortedMap<UnitNRShape,FacetParentVal> parents = new TreeMap<>();
-
- /** Holds a block of detailLevel counts aggregated to their parent level. */
- public static class FacetParentVal {
-
- /** The count of ranges that span all of the childCounts. In more technical terms, this is the number of leaf
- * cells found at this parent. Treat this like {@link Facets#topLeaves}. */
- public int parentLeaves;
-
- /** The length of {@link #childCounts}. If childCounts is not null then this is childCounts.length, otherwise it
- * says how long it would have been if it weren't null. */
- public int childCountsLen;
-
- /** The detail level counts. It will be null if there are none, and thus they are assumed 0. Most apps, when
- * presenting the information, will add {@link #topLeaves} and {@link #parentLeaves} to each count. */
- public int[] childCounts;
- //assert childCountsLen == childCounts.length
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder(2048);
- buf.append("Facets: level=" + detailLevel + " topLeaves=" + topLeaves + " parentCount=" + parents.size());
- for (Map.Entry<UnitNRShape, FacetParentVal> entry : parents.entrySet()) {
- buf.append('\n');
- if (buf.length() > 1000) {
- buf.append("...");
- break;
- }
- final FacetParentVal pVal = entry.getValue();
- buf.append(' ').append(entry.getKey()+" leafCount=" + pVal.parentLeaves);
- if (pVal.childCounts != null) {
- buf.append(' ').append(Arrays.toString(pVal.childCounts));
- }
- }
- return buf.toString();
- }
- }
-
}
Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java?rev=1659626&r1=1659625&r2=1659626&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java Fri Feb 13 17:44:01 2015
@@ -50,7 +50,7 @@ import org.apache.lucene.util.StringHelp
* Unlike "normal" spatial components in this module, this special-purpose one only works with {@link Shape}s
* created by the methods on this class, not from any {@link com.spatial4j.core.context.SpatialContext}.
*
- * @see org.apache.lucene.spatial.NumberRangePrefixTreeStrategy
+ * @see org.apache.lucene.spatial.prefix.NumberRangePrefixTreeStrategy
* @see <a href="https://issues.apache.org/jira/browse/LUCENE-5648">LUCENE-5648</a>
* @lucene.experimental
*/
Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java?rev=1659626&r1=1659625&r2=1659626&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java Fri Feb 13 17:44:01 2015
@@ -22,7 +22,6 @@ import java.util.Calendar;
import com.carrotsearch.randomizedtesting.annotations.Repeat;
import com.spatial4j.core.shape.Shape;
-import org.apache.lucene.spatial.NumberRangePrefixTreeStrategy;
import org.apache.lucene.spatial.prefix.tree.DateRangePrefixTree;
import org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape;
import org.apache.lucene.spatial.query.SpatialOperation;
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/DateRangeField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/DateRangeField.java?rev=1659626&r1=1659625&r2=1659626&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/DateRangeField.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/DateRangeField.java Fri Feb 13 17:44:01 2015
@@ -27,7 +27,7 @@ import com.spatial4j.core.shape.Shape;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.Query;
-import org.apache.lucene.spatial.NumberRangePrefixTreeStrategy;
+import org.apache.lucene.spatial.prefix.NumberRangePrefixTreeStrategy;
import org.apache.lucene.spatial.prefix.tree.DateRangePrefixTree;
import org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.NRShape;
import org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape;