You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/11/27 12:34:48 UTC
svn commit: r1642110 [9/12] - in /lucene/dev/branches/lucene6005/lucene:
analysis/uima/src/test/org/apache/lucene/analysis/uima/
backward-codecs/src/test/org/apache/lucene/index/
benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ benchmark/sr...
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java Thu Nov 27 11:34:43 2014
@@ -17,12 +17,14 @@ package org.apache.lucene.spatial.bbox;
* limitations under the License.
*/
-import org.apache.lucene.document.DoubleField;
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.BooleanClause;
@@ -92,9 +94,6 @@ public class BBoxStrategy extends Spatia
protected final String field_maxY;
protected final String field_xdl; // crosses dateline
- protected FieldType fieldType;//for the 4 numbers
- protected FieldType xdlFieldType;
-
public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix) {
super(ctx, fieldNamePrefix);
field_bbox = fieldNamePrefix;
@@ -103,35 +102,6 @@ public class BBoxStrategy extends Spatia
field_minY = fieldNamePrefix + SUFFIX_MINY;
field_maxY = fieldNamePrefix + SUFFIX_MAXY;
field_xdl = fieldNamePrefix + SUFFIX_XDL;
-
- FieldType fieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
- fieldType.setNumericPrecisionStep(8);//Solr's default
- fieldType.setDocValuesType(DocValuesType.NUMERIC);
- setFieldType(fieldType);
- }
-
- private int getPrecisionStep() {
- return fieldType.numericPrecisionStep();
- }
-
- public FieldType getFieldType() {
- return fieldType;
- }
-
- /** Used to customize the indexing options of the 4 number fields, and to a lesser degree the XDL field too. Search
- * requires indexed=true, and relevancy requires docValues. If these features aren't needed then disable them.
- * {@link FieldType#freeze()} is called on the argument. */
- public void setFieldType(FieldType fieldType) {
- fieldType.freeze();
- this.fieldType = fieldType;
- //only double's supported right now
- if (fieldType.numericType() != FieldType.NumericType.DOUBLE)
- throw new IllegalArgumentException("BBoxStrategy only supports doubles at this time.");
- //for xdlFieldType, copy some similar options. Don't do docValues since it isn't needed here.
- xdlFieldType = new FieldType(StringField.TYPE_NOT_STORED);
- xdlFieldType.setStored(fieldType.stored());
- xdlFieldType.setIndexOptions(fieldType.indexOptions());
- xdlFieldType.freeze();
}
//---------------------------------
@@ -139,42 +109,32 @@ public class BBoxStrategy extends Spatia
//---------------------------------
@Override
- public Field[] createIndexableFields(Shape shape) {
- return createIndexableFields(shape.getBoundingBox());
+ public void addFields(Document2 doc, Shape shape) {
+ addFields(doc, shape.getBoundingBox());
}
- public Field[] createIndexableFields(Rectangle bbox) {
- Field[] fields = new Field[5];
- fields[0] = new ComboField(field_minX, bbox.getMinX(), fieldType);
- fields[1] = new ComboField(field_maxX, bbox.getMaxX(), fieldType);
- fields[2] = new ComboField(field_minY, bbox.getMinY(), fieldType);
- fields[3] = new ComboField(field_maxY, bbox.getMaxY(), fieldType);
- fields[4] = new ComboField(field_xdl, bbox.getCrossesDateLine()?"T":"F", xdlFieldType);
- return fields;
- }
-
- /** Field subclass circumventing Field limitations. This one instance can have any combination of indexed, stored,
- * and docValues.
- */
- private static class ComboField extends Field {
- private ComboField(String name, Object value, FieldType type) {
- super(name, type);//this expert constructor allows us to have a field that has docValues & indexed/stored
- super.fieldsData = value;
- }
-
- //Is this a hack? We assume that numericValue() is only called for DocValues purposes.
- @Override
- public Number numericDocValue() {
- //Numeric DocValues only supports Long,
- final Number number = super.numericValue();
- if (number == null)
- return null;
- if (fieldType().numericType() == FieldType.NumericType.DOUBLE)
- return Double.doubleToLongBits(number.doubleValue());
- if (fieldType().numericType() == FieldType.NumericType.FLOAT)
- return Float.floatToIntBits(number.floatValue());
- return number.longValue();
- }
+ public void addFields(Document2 doc, Rectangle bbox) {
+ doc.addDouble(field_minX, bbox.getMinX());
+ doc.addDouble(field_maxX, bbox.getMaxX());
+ doc.addDouble(field_minY, bbox.getMinY());
+ doc.addDouble(field_maxY, bbox.getMaxY());
+ doc.addAtom(field_xdl, bbox.getCrossesDateLine()?"T":"F");
+ }
+
+ public void setDocValuesType(FieldTypes fieldTypes, DocValuesType dvType) {
+ fieldTypes.setDocValuesType(field_minX, dvType);
+ fieldTypes.setDocValuesType(field_minY, dvType);
+ fieldTypes.setDocValuesType(field_maxX, dvType);
+ fieldTypes.setDocValuesType(field_maxY, dvType);
+ fieldTypes.setDocValuesType(field_xdl, dvType);
+ }
+
+ public void setIndexOptions(FieldTypes fieldTypes, IndexOptions indexOptions) {
+ fieldTypes.setIndexOptions(field_minX, indexOptions);
+ fieldTypes.setIndexOptions(field_maxX, indexOptions);
+ fieldTypes.setIndexOptions(field_minY, indexOptions);
+ fieldTypes.setIndexOptions(field_maxY, indexOptions);
+ fieldTypes.setIndexOptions(field_xdl, indexOptions);
}
//---------------------------------
@@ -208,13 +168,13 @@ public class BBoxStrategy extends Spatia
//---------------------------------
@Override
- public Filter makeFilter(SpatialArgs args) {
- return new QueryWrapperFilter(makeSpatialQuery(args));
+ public Filter makeFilter(FieldTypes fieldTypes, SpatialArgs args) {
+ return new QueryWrapperFilter(makeSpatialQuery(fieldTypes, args));
}
@Override
- public ConstantScoreQuery makeQuery(SpatialArgs args) {
- return new ConstantScoreQuery(makeSpatialQuery(args));
+ public ConstantScoreQuery makeQuery(FieldTypes fieldTypes, SpatialArgs args) {
+ return new ConstantScoreQuery(makeSpatialQuery(fieldTypes, args));
}
// Utility on SpatialStrategy?
@@ -222,7 +182,7 @@ public class BBoxStrategy extends Spatia
// return new FilteredQuery(new FunctionQuery(valueSource), makeFilter(args));
// }
- private Query makeSpatialQuery(SpatialArgs args) {
+ private Query makeSpatialQuery(FieldTypes fieldTypes, SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
@@ -233,13 +193,14 @@ public class BBoxStrategy extends Spatia
// Useful for understanding Relations:
// http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm
SpatialOperation op = args.getOperation();
- if( op == SpatialOperation.BBoxIntersects ) spatial = makeIntersects(bbox);
- else if( op == SpatialOperation.BBoxWithin ) spatial = makeWithin(bbox);
- else if( op == SpatialOperation.Contains ) spatial = makeContains(bbox);
- else if( op == SpatialOperation.Intersects ) spatial = makeIntersects(bbox);
- else if( op == SpatialOperation.IsEqualTo ) spatial = makeEquals(bbox);
- else if( op == SpatialOperation.IsDisjointTo ) spatial = makeDisjoint(bbox);
- else if( op == SpatialOperation.IsWithin ) spatial = makeWithin(bbox);
+
+ if( op == SpatialOperation.BBoxIntersects ) spatial = makeIntersects(fieldTypes, bbox);
+ else if( op == SpatialOperation.BBoxWithin ) spatial = makeWithin(fieldTypes, bbox);
+ else if( op == SpatialOperation.Contains ) spatial = makeContains(fieldTypes, bbox);
+ else if( op == SpatialOperation.Intersects ) spatial = makeIntersects(fieldTypes, bbox);
+ else if( op == SpatialOperation.IsEqualTo ) spatial = makeEquals(fieldTypes, bbox);
+ else if( op == SpatialOperation.IsDisjointTo ) spatial = makeDisjoint(fieldTypes, bbox);
+ else if( op == SpatialOperation.IsWithin ) spatial = makeWithin(fieldTypes, bbox);
else { //no Overlaps support yet
throw new UnsupportedSpatialOperation(op);
}
@@ -251,15 +212,15 @@ public class BBoxStrategy extends Spatia
*
* @return the spatial query
*/
- Query makeContains(Rectangle bbox) {
+ Query makeContains(FieldTypes fieldTypes, Rectangle bbox) {
// general case
// docMinX <= queryExtent.getMinX() AND docMinY <= queryExtent.getMinY() AND docMaxX >= queryExtent.getMaxX() AND docMaxY >= queryExtent.getMaxY()
// Y conditions
// docMinY <= queryExtent.getMinY() AND docMaxY >= queryExtent.getMaxY()
- Query qMinY = NumericRangeQuery.newDoubleRange(field_minY, getPrecisionStep(), null, bbox.getMinY(), false, true);
- Query qMaxY = NumericRangeQuery.newDoubleRange(field_maxY, getPrecisionStep(), bbox.getMaxY(), null, true, false);
+ Query qMinY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minY, null, false, bbox.getMinY(), true));
+ Query qMaxY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxY, bbox.getMaxY(), true, null, false));
Query yConditions = this.makeQuery(BooleanClause.Occur.MUST, qMinY, qMaxY);
// X conditions
@@ -271,8 +232,8 @@ public class BBoxStrategy extends Spatia
// X Conditions for documents that do not cross the date line,
// documents that contain the min X and max X of the query envelope,
// docMinX <= queryExtent.getMinX() AND docMaxX >= queryExtent.getMaxX()
- Query qMinX = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), null, bbox.getMinX(), false, true);
- Query qMaxX = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), bbox.getMaxX(), null, true, false);
+ Query qMinX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, null, false, bbox.getMinX(), true));
+ Query qMaxX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, bbox.getMaxX(), true, null, false));
Query qMinMax = this.makeQuery(BooleanClause.Occur.MUST, qMinX, qMaxX);
Query qNonXDL = this.makeXDL(false, qMinMax);
@@ -283,8 +244,8 @@ public class BBoxStrategy extends Spatia
// the left portion of the document contains the min X of the query
// OR the right portion of the document contains the max X of the query,
// docMinXLeft <= queryExtent.getMinX() OR docMaxXRight >= queryExtent.getMaxX()
- Query qXDLLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), null, bbox.getMinX(), false, true);
- Query qXDLRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), bbox.getMaxX(), null, true, false);
+ Query qXDLLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, null, false, bbox.getMinX(), true));
+ Query qXDLRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, bbox.getMaxX(), true, null, false));
Query qXDLLeftRight = this.makeQuery(BooleanClause.Occur.SHOULD, qXDLLeft, qXDLRight);
Query qXDL = this.makeXDL(true, qXDLLeftRight);
@@ -292,7 +253,7 @@ public class BBoxStrategy extends Spatia
if (bbox.getMinX() == bbox.getMaxX() && Math.abs(bbox.getMinX()) == 180) {
double edge = bbox.getMinX() * -1;//opposite dateline edge
qEdgeDL = makeQuery(BooleanClause.Occur.SHOULD,
- makeNumberTermQuery(field_minX, edge), makeNumberTermQuery(field_maxX, edge));
+ makeNumberTermQuery(fieldTypes, field_minX, edge), makeNumberTermQuery(fieldTypes, field_maxX, edge));
}
// apply the non-XDL and XDL conditions
@@ -307,12 +268,12 @@ public class BBoxStrategy extends Spatia
// the left portion of the document contains the min X of the query
// AND the right portion of the document contains the max X of the query,
// docMinXLeft <= queryExtent.getMinX() AND docMaxXRight >= queryExtent.getMaxX()
- Query qXDLLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), null, bbox.getMinX(), false, true);
- Query qXDLRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), bbox.getMaxX(), null, true, false);
+ Query qXDLLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, null, false, bbox.getMinX(), true));
+ Query qXDLRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, bbox.getMaxX(), true, null, false));
Query qXDLLeftRight = this.makeXDL(true, this.makeQuery(BooleanClause.Occur.MUST, qXDLLeft, qXDLRight));
Query qWorld = makeQuery(BooleanClause.Occur.MUST,
- makeNumberTermQuery(field_minX, -180), makeNumberTermQuery(field_maxX, 180));
+ makeNumberTermQuery(fieldTypes, field_minX, -180), makeNumberTermQuery(fieldTypes, field_maxX, 180));
xConditions = makeQuery(BooleanClause.Occur.SHOULD, qXDLLeftRight, qWorld);
}
@@ -326,15 +287,15 @@ public class BBoxStrategy extends Spatia
*
* @return the spatial query
*/
- Query makeDisjoint(Rectangle bbox) {
+ Query makeDisjoint(FieldTypes fieldTypes, Rectangle bbox) {
// general case
// docMinX > queryExtent.getMaxX() OR docMaxX < queryExtent.getMinX() OR docMinY > queryExtent.getMaxY() OR docMaxY < queryExtent.getMinY()
// Y conditions
// docMinY > queryExtent.getMaxY() OR docMaxY < queryExtent.getMinY()
- Query qMinY = NumericRangeQuery.newDoubleRange(field_minY, getPrecisionStep(), bbox.getMaxY(), null, false, false);
- Query qMaxY = NumericRangeQuery.newDoubleRange(field_maxY, getPrecisionStep(), null, bbox.getMinY(), false, false);
+ Query qMinY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minY, bbox.getMaxY(), false, null, false));
+ Query qMaxY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxY, null, false, bbox.getMinY(), false));
Query yConditions = this.makeQuery(BooleanClause.Occur.SHOULD, qMinY, qMaxY);
// X conditions
@@ -345,18 +306,18 @@ public class BBoxStrategy extends Spatia
// X Conditions for documents that do not cross the date line,
// docMinX > queryExtent.getMaxX() OR docMaxX < queryExtent.getMinX()
- Query qMinX = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMaxX(), null, false, false);
+ Query qMinX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMaxX(), false, null, false));
if (bbox.getMinX() == -180.0 && ctx.isGeo()) {//touches dateline; -180 == 180
BooleanQuery bq = new BooleanQuery();
bq.add(qMinX, BooleanClause.Occur.MUST);
- bq.add(makeNumberTermQuery(field_maxX, 180.0), BooleanClause.Occur.MUST_NOT);
+ bq.add(makeNumberTermQuery(fieldTypes, field_maxX, 180.0), BooleanClause.Occur.MUST_NOT);
qMinX = bq;
}
- Query qMaxX = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMinX(), false, false);
+ Query qMaxX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, bbox.getMinX(), false));
if (bbox.getMaxX() == 180.0 && ctx.isGeo()) {//touches dateline; -180 == 180
BooleanQuery bq = new BooleanQuery();
bq.add(qMaxX, BooleanClause.Occur.MUST);
- bq.add(makeNumberTermQuery(field_minX, -180.0), BooleanClause.Occur.MUST_NOT);
+ bq.add(makeNumberTermQuery(fieldTypes, field_minX, -180.0), BooleanClause.Occur.MUST_NOT);
qMaxX = bq;
}
Query qMinMax = this.makeQuery(BooleanClause.Occur.SHOULD, qMinX, qMaxX);
@@ -373,8 +334,8 @@ public class BBoxStrategy extends Spatia
// where: docMaxXLeft = 180.0, docMinXRight = -180.0
// (docMaxXLeft < queryExtent.getMinX()) equates to (180.0 < queryExtent.getMinX()) and is ignored
// (docMinXRight > queryExtent.getMaxX()) equates to (-180.0 > queryExtent.getMaxX()) and is ignored
- Query qMinXLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMaxX(), null, false, false);
- Query qMaxXRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMinX(), false, false);
+ Query qMinXLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMaxX(), false, null, false));
+ Query qMaxXRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, bbox.getMinX(), false));
Query qLeftRight = this.makeQuery(BooleanClause.Occur.MUST, qMinXLeft, qMaxXRight);
Query qXDL = this.makeXDL(true, qLeftRight);
@@ -388,10 +349,10 @@ public class BBoxStrategy extends Spatia
// the document must be disjoint to both the left and right query portions
// (docMinX > queryExtent.getMaxX()Left OR docMaxX < queryExtent.getMinX()) AND (docMinX > queryExtent.getMaxX() OR docMaxX < queryExtent.getMinX()Left)
// where: queryExtent.getMaxX()Left = 180.0, queryExtent.getMinX()Left = -180.0
- Query qMinXLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), 180.0, null, false, false);
- Query qMaxXLeft = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMinX(), false, false);
- Query qMinXRight = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMaxX(), null, false, false);
- Query qMaxXRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, -180.0, false, false);
+ Query qMinXLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, 180.0, false, null, false));
+ Query qMaxXLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false,bbox.getMinX(), false));
+ Query qMinXRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMaxX(), false, null, false));
+ Query qMaxXRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, -180.0, false));
Query qLeft = this.makeQuery(BooleanClause.Occur.SHOULD, qMinXLeft, qMaxXLeft);
Query qRight = this.makeQuery(BooleanClause.Occur.SHOULD, qMinXRight, qMaxXRight);
Query qLeftRight = this.makeQuery(BooleanClause.Occur.MUST, qLeft, qRight);
@@ -410,13 +371,13 @@ public class BBoxStrategy extends Spatia
*
* @return the spatial query
*/
- Query makeEquals(Rectangle bbox) {
+ Query makeEquals(FieldTypes fieldTypes, Rectangle bbox) {
// docMinX = queryExtent.getMinX() AND docMinY = queryExtent.getMinY() AND docMaxX = queryExtent.getMaxX() AND docMaxY = queryExtent.getMaxY()
- Query qMinX = makeNumberTermQuery(field_minX, bbox.getMinX());
- Query qMinY = makeNumberTermQuery(field_minY, bbox.getMinY());
- Query qMaxX = makeNumberTermQuery(field_maxX, bbox.getMaxX());
- Query qMaxY = makeNumberTermQuery(field_maxY, bbox.getMaxY());
+ Query qMinX = makeNumberTermQuery(fieldTypes, field_minX, bbox.getMinX());
+ Query qMinY = makeNumberTermQuery(fieldTypes, field_minY, bbox.getMinY());
+ Query qMaxX = makeNumberTermQuery(fieldTypes, field_maxX, bbox.getMaxX());
+ Query qMaxY = makeNumberTermQuery(fieldTypes, field_maxY, bbox.getMaxY());
return makeQuery(BooleanClause.Occur.MUST, qMinX, qMinY, qMaxX, qMaxY);
}
@@ -425,7 +386,7 @@ public class BBoxStrategy extends Spatia
*
* @return the spatial query
*/
- Query makeIntersects(Rectangle bbox) {
+ Query makeIntersects(FieldTypes fieldTypes, Rectangle bbox) {
// the original intersects query does not work for envelopes that cross the date line,
// switch to a NOT Disjoint query
@@ -445,7 +406,7 @@ public class BBoxStrategy extends Spatia
BooleanQuery qNotDisjoint = new BooleanQuery();
qNotDisjoint.add(qHasEnv, BooleanClause.Occur.MUST);
- Query qDisjoint = makeDisjoint(bbox);
+ Query qDisjoint = makeDisjoint(fieldTypes, bbox);
qNotDisjoint.add(qDisjoint, BooleanClause.Occur.MUST_NOT);
//Query qDisjoint = makeDisjoint();
@@ -476,15 +437,15 @@ public class BBoxStrategy extends Spatia
*
* @return the spatial query
*/
- Query makeWithin(Rectangle bbox) {
+ Query makeWithin(FieldTypes fieldTypes, Rectangle bbox) {
// general case
// docMinX >= queryExtent.getMinX() AND docMinY >= queryExtent.getMinY() AND docMaxX <= queryExtent.getMaxX() AND docMaxY <= queryExtent.getMaxY()
// Y conditions
// docMinY >= queryExtent.getMinY() AND docMaxY <= queryExtent.getMaxY()
- Query qMinY = NumericRangeQuery.newDoubleRange(field_minY, getPrecisionStep(), bbox.getMinY(), null, true, false);
- Query qMaxY = NumericRangeQuery.newDoubleRange(field_maxY, getPrecisionStep(), null, bbox.getMaxY(), false, true);
+ Query qMinY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minY, bbox.getMinY(), true, null, false));
+ Query qMaxY = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxY, null, false, bbox.getMaxY(), true));
Query yConditions = this.makeQuery(BooleanClause.Occur.MUST, qMinY, qMaxY);
// X conditions
@@ -498,8 +459,8 @@ public class BBoxStrategy extends Spatia
// queries that do not cross the date line
// docMinX >= queryExtent.getMinX() AND docMaxX <= queryExtent.getMaxX()
- Query qMinX = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMinX(), null, true, false);
- Query qMaxX = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMaxX(), false, true);
+ Query qMinX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMinX(), true, null, false));
+ Query qMaxX = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, bbox.getMaxX(), true));
Query qMinMax = this.makeQuery(BooleanClause.Occur.MUST, qMinX, qMaxX);
double edge = 0;//none, otherwise opposite dateline of query
@@ -509,7 +470,7 @@ public class BBoxStrategy extends Spatia
edge = -180;
if (edge != 0 && ctx.isGeo()) {
Query edgeQ = makeQuery(BooleanClause.Occur.MUST,
- makeNumberTermQuery(field_minX, edge), makeNumberTermQuery(field_maxX, edge));
+ makeNumberTermQuery(fieldTypes, field_minX, edge), makeNumberTermQuery(fieldTypes, field_maxX, edge));
qMinMax = makeQuery(BooleanClause.Occur.SHOULD, qMinMax, edgeQ);
}
@@ -522,14 +483,14 @@ public class BBoxStrategy extends Spatia
// the document should be within the left portion of the query
// docMinX >= queryExtent.getMinX() AND docMaxX <= 180.0
- Query qMinXLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMinX(), null, true, false);
- Query qMaxXLeft = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, 180.0, false, true);
+ Query qMinXLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMinX(), true, null, false));
+ Query qMaxXLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, 180.0, true));
Query qLeft = this.makeQuery(BooleanClause.Occur.MUST, qMinXLeft, qMaxXLeft);
// the document should be within the right portion of the query
// docMinX >= -180.0 AND docMaxX <= queryExtent.getMaxX()
- Query qMinXRight = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), -180.0, null, true, false);
- Query qMaxXRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMaxX(), false, true);
+ Query qMinXRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, -180.0, true, null, false));
+ Query qMaxXRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, bbox.getMaxX(), true));
Query qRight = this.makeQuery(BooleanClause.Occur.MUST, qMinXRight, qMaxXRight);
// either left or right conditions should occur,
@@ -542,8 +503,8 @@ public class BBoxStrategy extends Spatia
// AND the right portion of the document must be within the right portion of the query
// docMinXLeft >= queryExtent.getMinX() AND docMaxXLeft <= 180.0
// AND docMinXRight >= -180.0 AND docMaxXRight <= queryExtent.getMaxX()
- Query qXDLLeft = NumericRangeQuery.newDoubleRange(field_minX, getPrecisionStep(), bbox.getMinX(), null, true, false);
- Query qXDLRight = NumericRangeQuery.newDoubleRange(field_maxX, getPrecisionStep(), null, bbox.getMaxX(), false, true);
+ Query qXDLLeft = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_minX, bbox.getMinX(), true, null, false));
+ Query qXDLRight = new ConstantScoreQuery(fieldTypes.newRangeFilter(field_maxX, null, false, bbox.getMaxX(), true));
Query qXDLLeftRight = this.makeQuery(BooleanClause.Occur.MUST, qXDLLeft, qXDLRight);
Query qXDL = this.makeXDL(true, qXDLLeftRight);
@@ -585,12 +546,9 @@ public class BBoxStrategy extends Spatia
return bq;
}
- private Query makeNumberTermQuery(String field, double number) {
- BytesRefBuilder bytes = new BytesRefBuilder();
- NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(number), 0, bytes);
- return new TermQuery(new Term(field, bytes.get()));
+ private Query makeNumberTermQuery(FieldTypes fieldTypes, String field, double number) {
+ return new TermQuery(new Term(field, Document2.doubleToBytes(number)));
}
-
}
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java Thu Nov 27 11:34:43 2014
@@ -17,18 +17,19 @@ package org.apache.lucene.spatial.bbox;
* limitations under the License.
*/
-import com.spatial4j.core.shape.Rectangle;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.document.Document2;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.util.Bits;
-
-import java.io.IOException;
-import java.util.Map;
+import com.spatial4j.core.shape.Rectangle;
/**
* A ValueSource in which the indexed Rectangle is returned from
@@ -68,8 +69,10 @@ class BBoxValueSource extends ValueSourc
return null;
} else {
rect.reset(
- Double.longBitsToDouble(minX.get(doc)), Double.longBitsToDouble(maxX.get(doc)),
- Double.longBitsToDouble(minY.get(doc)), Double.longBitsToDouble(maxY.get(doc)));
+ Document2.longToDouble(minX.get(doc)),
+ Document2.longToDouble(maxX.get(doc)),
+ Document2.longToDouble(minY.get(doc)),
+ Document2.longToDouble(maxY.get(doc)));
return rect;
}
}
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java Thu Nov 27 11:34:43 2014
@@ -22,8 +22,10 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.queries.function.ValueSource;
@@ -115,9 +117,9 @@ public abstract class PrefixTreeStrategy
}
@Override
- public Field[] createIndexableFields(Shape shape) {
+ public void addFields(Document2 doc, Shape shape) {
double distErr = SpatialArgs.calcDistanceFromErrPct(shape, distErrPct, ctx);
- return createIndexableFields(shape, distErr);
+ addFields(doc, shape, distErr);
}
/**
@@ -127,11 +129,14 @@ public abstract class PrefixTreeStrategy
* simply/aggregate sets of complete leaves in a cell to its parent, resulting in ~20-25%
* fewer cells. It will likely be removed in the future.
*/
- public Field[] createIndexableFields(Shape shape, double distErr) {
+ public void addFields(Document2 doc, Shape shape, double distErr) {
int detailLevel = grid.getLevelForDistance(distErr);
- TokenStream tokenStream = createTokenStream(shape, detailLevel);
- Field field = new Field(getFieldName(), tokenStream, FIELD_TYPE);
- return new Field[]{field};
+ FieldTypes fieldTypes = doc.getFieldTypes();
+ fieldTypes.disableNorms(getFieldName());
+ fieldTypes.disableHighlighting(getFieldName());
+ fieldTypes.setIndexOptions(getFieldName(), IndexOptions.DOCS);
+ fieldTypes.setMultiValued(getFieldName());
+ doc.addLargeText(getFieldName(), createTokenStream(shape, detailLevel));
}
protected TokenStream createTokenStream(Shape shape, int detailLevel) {
@@ -139,16 +144,6 @@ public abstract class PrefixTreeStrategy
return new CellTokenStream().setCells(cells);
}
- /* Indexed, tokenized, not stored. */
- public static final FieldType FIELD_TYPE = new FieldType();
-
- static {
- FIELD_TYPE.setTokenized(true);
- FIELD_TYPE.setOmitNorms(true);
- FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
- FIELD_TYPE.freeze();
- }
-
@Override
public ValueSource makeDistanceValueSource(Point queryPoint, double multiplier) {
PointPrefixTreeFieldCacheProvider p = provider.get( getFieldName() );
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java Thu Nov 27 11:34:43 2014
@@ -17,9 +17,11 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Shape;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.search.Filter;
import org.apache.lucene.spatial.prefix.tree.Cell;
import org.apache.lucene.spatial.prefix.tree.CellIterator;
@@ -28,9 +30,8 @@ import org.apache.lucene.spatial.prefix.
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
-
-import java.util.ArrayList;
-import java.util.List;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
/**
* A {@link PrefixTreeStrategy} which uses {@link AbstractVisitingPrefixTreeFilter}.
@@ -162,7 +163,7 @@ public class RecursivePrefixTreeStrategy
}
@Override
- public Filter makeFilter(SpatialArgs args) {
+ public Filter makeFilter(FieldTypes fieldTypes, SpatialArgs args) {
final SpatialOperation op = args.getOperation();
Shape shape = args.getShape();
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java Thu Nov 27 11:34:43 2014
@@ -17,9 +17,10 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Shape;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.queries.TermsFilter;
import org.apache.lucene.search.Filter;
import org.apache.lucene.spatial.prefix.tree.Cell;
@@ -30,9 +31,8 @@ import org.apache.lucene.spatial.query.S
import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
-
-import java.util.ArrayList;
-import java.util.List;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
/**
* A basic implementation of {@link PrefixTreeStrategy} using a large
@@ -55,7 +55,7 @@ public class TermQueryPrefixTreeStrategy
}
@Override
- public Filter makeFilter(SpatialArgs args) {
+ public Filter makeFilter(FieldTypes fieldTypes, SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/LegacyCell.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/LegacyCell.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/LegacyCell.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/LegacyCell.java Thu Nov 27 11:34:43 2014
@@ -17,13 +17,14 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.StringHelper;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.SpatialRelation;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.StringHelper;
-
-import java.util.Collection;
/** The base for the original two SPT's: Geohash & Quad. Don't subclass this for new SPTs.
* @lucene.internal */
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/QuadPrefixTree.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/QuadPrefixTree.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/QuadPrefixTree.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/QuadPrefixTree.java Thu Nov 27 11:34:43 2014
@@ -272,7 +272,6 @@ public class QuadPrefixTree extends Lega
BytesRef token = getTokenBytesNoLeaf(null);
double xmin = QuadPrefixTree.this.xmin;
double ymin = QuadPrefixTree.this.ymin;
-
for (int i = 0; i < token.length; i++) {
byte c = token.bytes[token.offset + i];
switch (c) {
@@ -289,7 +288,7 @@ public class QuadPrefixTree extends Lega
xmin += levelW[i];
break;
default:
- throw new RuntimeException("unexpected char: " + c);
+ throw new RuntimeException("unexpected char: " + (char) c);
}
}
int len = token.length;
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java Thu Nov 27 11:34:43 2014
@@ -17,15 +17,20 @@ package org.apache.lucene.spatial.serial
* limitations under the License.
*/
-import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.io.BinaryCodec;
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Shape;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.util.Map;
import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Field;
-import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.index.BinaryDocValues;
+import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.DocIdSet;
@@ -40,14 +45,10 @@ import org.apache.lucene.spatial.util.Sh
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.util.Map;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.io.BinaryCodec;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
/**
@@ -76,7 +77,7 @@ public class SerializedDVStrategy extend
}
@Override
- public Field[] createIndexableFields(Shape shape) {
+ public void addFields(Document2 doc, Shape shape) {
int bufSize = Math.max(128, (int) (this.indexLastBufSize * 1.5));//50% headroom over last
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(bufSize);
final BytesRef bytesRef = new BytesRef();//receiver of byteStream's bytes
@@ -95,7 +96,8 @@ public class SerializedDVStrategy extend
throw new RuntimeException(e);
}
this.indexLastBufSize = bytesRef.length;//cache heuristic
- return new Field[]{new BinaryDocValuesField(getFieldName(), bytesRef)};
+ doc.getFieldTypes().disableSorting(getFieldName());
+ doc.addBinary(getFieldName(), bytesRef);
}
@Override
@@ -105,7 +107,7 @@ public class SerializedDVStrategy extend
}
@Override
- public Query makeQuery(SpatialArgs args) {
+ public Query makeQuery(FieldTypes fieldTypes, SpatialArgs args) {
throw new UnsupportedOperationException("This strategy can't return a query that operates" +
" efficiently. Instead try a Filter or ValueSource.");
}
@@ -116,7 +118,7 @@ public class SerializedDVStrategy extend
* to prevent misuse because the filter can't efficiently work via iteration.
*/
@Override
- public Filter makeFilter(final SpatialArgs args) {
+ public Filter makeFilter(FieldTypes fieldTypes, final SpatialArgs args) {
ValueSource shapeValueSource = makeShapeValueSource();
ShapePredicateValueSource predicateValueSource = new ShapePredicateValueSource(
shapeValueSource, args.getOperation(), args.getShape());
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java Thu Nov 27 11:34:43 2014
@@ -17,18 +17,19 @@ package org.apache.lucene.spatial.vector
* limitations under the License.
*/
-import com.spatial4j.core.distance.DistanceCalculator;
-import com.spatial4j.core.shape.Point;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.document.Document2;
+import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.util.Bits;
-
-import java.io.IOException;
-import java.util.Map;
+import com.spatial4j.core.distance.DistanceCalculator;
+import com.spatial4j.core.shape.Point;
/**
* An implementation of the Lucene ValueSource model that returns the distance
@@ -88,7 +89,7 @@ public class DistanceValueSource extends
// make sure it has minX and area
if (validX.get(doc)) {
assert validY.get(doc);
- return calculator.distance(from, Double.longBitsToDouble(ptX.get(doc)), Double.longBitsToDouble(ptY.get(doc))) * multiplier;
+ return calculator.distance(from, Document2.longToDouble(ptX.get(doc)), Document2.longToDouble(ptY.get(doc))) * multiplier;
}
return nullValue;
}
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java Thu Nov 27 11:34:43 2014
@@ -17,14 +17,10 @@ package org.apache.lucene.spatial.vector
* limitations under the License.
*/
-import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.shape.Circle;
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Rectangle;
-import com.spatial4j.core.shape.Shape;
-import org.apache.lucene.document.DoubleField;
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.queries.function.FunctionQuery;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.BooleanClause;
@@ -42,6 +38,11 @@ import org.apache.lucene.spatial.query.S
import org.apache.lucene.spatial.query.UnsupportedSpatialOperation;
import org.apache.lucene.spatial.util.CachingDoubleValueSource;
import org.apache.lucene.spatial.util.ValueSourceFilter;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Circle;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Rectangle;
+import com.spatial4j.core.shape.Shape;
/**
* Simple {@link SpatialStrategy} which represents Points in two numeric {@link
@@ -103,20 +104,18 @@ public class PointVectorStrategy extends
}
@Override
- public Field[] createIndexableFields(Shape shape) {
- if (shape instanceof Point)
- return createIndexableFields((Point) shape);
+ public void addFields(Document2 doc, Shape shape) {
+ if (shape instanceof Point) {
+ addFields(doc, (Point) shape);
+ return;
+ }
throw new UnsupportedOperationException("Can only index Point, not " + shape);
}
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */
- public Field[] createIndexableFields(Point point) {
- FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
- doubleFieldType.setNumericPrecisionStep(precisionStep);
- Field[] f = new Field[2];
- f[0] = new DoubleField(fieldNameX, point.getX(), doubleFieldType);
- f[1] = new DoubleField(fieldNameY, point.getY(), doubleFieldType);
- return f;
+ public void addFields(Document2 doc, Point point) {
+ doc.addDouble(fieldNameX, point.getX());
+ doc.addDouble(fieldNameY, point.getY());
}
@Override
@@ -125,9 +124,9 @@ public class PointVectorStrategy extends
}
@Override
- public Filter makeFilter(SpatialArgs args) {
+ public Filter makeFilter(FieldTypes fieldTypes, SpatialArgs args) {
//unwrap the CSQ from makeQuery
- ConstantScoreQuery csq = makeQuery(args);
+ ConstantScoreQuery csq = makeQuery(fieldTypes, args);
Filter filter = csq.getFilter();
if (filter != null)
return filter;
@@ -136,7 +135,7 @@ public class PointVectorStrategy extends
}
@Override
- public ConstantScoreQuery makeQuery(SpatialArgs args) {
+ public ConstantScoreQuery makeQuery(FieldTypes fieldTypes, SpatialArgs args) {
if(! SpatialOperation.is( args.getOperation(),
SpatialOperation.Intersects,
SpatialOperation.IsWithin ))
@@ -144,12 +143,12 @@ public class PointVectorStrategy extends
Shape shape = args.getShape();
if (shape instanceof Rectangle) {
Rectangle bbox = (Rectangle) shape;
- return new ConstantScoreQuery(makeWithin(bbox));
+ return new ConstantScoreQuery(makeWithin(fieldTypes, bbox));
} else if (shape instanceof Circle) {
Circle circle = (Circle)shape;
Rectangle bbox = circle.getBoundingBox();
ValueSourceFilter vsf = new ValueSourceFilter(
- new QueryWrapperFilter(makeWithin(bbox)),
+ new QueryWrapperFilter(makeWithin(fieldTypes, bbox)),
makeDistanceValueSource(circle.getCenter()),
0,
circle.getRadius() );
@@ -161,7 +160,7 @@ public class PointVectorStrategy extends
}
//TODO this is basically old code that hasn't been verified well and should probably be removed
- public Query makeQueryDistanceScore(SpatialArgs args) {
+ public Query makeQueryDistanceScore(FieldTypes fieldTypes, SpatialArgs args) {
// For starters, just limit the bbox
Shape shape = args.getShape();
if (!(shape instanceof Rectangle || shape instanceof Circle)) {
@@ -183,12 +182,12 @@ public class PointVectorStrategy extends
if( SpatialOperation.is( op,
SpatialOperation.BBoxWithin,
SpatialOperation.BBoxIntersects ) ) {
- spatial = makeWithin(bbox);
+ spatial = makeWithin(fieldTypes, bbox);
}
else if( SpatialOperation.is( op,
SpatialOperation.Intersects,
SpatialOperation.IsWithin ) ) {
- spatial = makeWithin(bbox);
+ spatial = makeWithin(fieldTypes, bbox);
if( args.getShape() instanceof Circle) {
Circle circle = (Circle)args.getShape();
@@ -202,7 +201,7 @@ public class PointVectorStrategy extends
}
}
else if( op == SpatialOperation.IsDisjointTo ) {
- spatial = makeDisjoint(bbox);
+ spatial = makeDisjoint(fieldTypes, bbox);
}
if( spatial == null ) {
@@ -225,39 +224,39 @@ public class PointVectorStrategy extends
/**
* Constructs a query to retrieve documents that fully contain the input envelope.
*/
- private Query makeWithin(Rectangle bbox) {
+ private Query makeWithin(FieldTypes fieldTypes, Rectangle bbox) {
BooleanQuery bq = new BooleanQuery();
BooleanClause.Occur MUST = BooleanClause.Occur.MUST;
if (bbox.getCrossesDateLine()) {
//use null as performance trick since no data will be beyond the world bounds
- bq.add(rangeQuery(fieldNameX, null/*-180*/, bbox.getMaxX()), BooleanClause.Occur.SHOULD );
- bq.add(rangeQuery(fieldNameX, bbox.getMinX(), null/*+180*/), BooleanClause.Occur.SHOULD );
+ bq.add(rangeQuery(fieldTypes, fieldNameX, null/*-180*/, bbox.getMaxX()), BooleanClause.Occur.SHOULD );
+ bq.add(rangeQuery(fieldTypes, fieldNameX, bbox.getMinX(), null/*+180*/), BooleanClause.Occur.SHOULD );
bq.setMinimumNumberShouldMatch(1);//must match at least one of the SHOULD
} else {
- bq.add(rangeQuery(fieldNameX, bbox.getMinX(), bbox.getMaxX()), MUST);
+ bq.add(rangeQuery(fieldTypes, fieldNameX, bbox.getMinX(), bbox.getMaxX()), MUST);
}
- bq.add(rangeQuery(fieldNameY, bbox.getMinY(), bbox.getMaxY()), MUST);
+ bq.add(rangeQuery(fieldTypes, fieldNameY, bbox.getMinY(), bbox.getMaxY()), MUST);
+
return bq;
}
- private NumericRangeQuery<Double> rangeQuery(String fieldName, Double min, Double max) {
- return NumericRangeQuery.newDoubleRange(
+ private Query rangeQuery(FieldTypes fieldTypes, String fieldName, Double min, Double max) {
+ return new ConstantScoreQuery(fieldTypes.newRangeFilter(
fieldName,
- precisionStep,
min,
- max,
true,
- true);//inclusive
+ max,
+ true));//inclusive
}
/**
* Constructs a query to retrieve documents that fully contain the input envelope.
*/
- private Query makeDisjoint(Rectangle bbox) {
+ private Query makeDisjoint(FieldTypes fieldTypes, Rectangle bbox) {
if (bbox.getCrossesDateLine())
throw new UnsupportedOperationException("makeDisjoint doesn't handle dateline cross");
- Query qX = rangeQuery(fieldNameX, bbox.getMinX(), bbox.getMaxX());
- Query qY = rangeQuery(fieldNameY, bbox.getMinY(), bbox.getMaxY());
+ Query qX = rangeQuery(fieldTypes, fieldNameX, bbox.getMinX(), bbox.getMaxX());
+ Query qY = rangeQuery(fieldTypes, fieldNameY, bbox.getMinY(), bbox.getMaxY());
BooleanQuery bq = new BooleanQuery();
bq.add(qX,BooleanClause.Occur.MUST_NOT);
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java Thu Nov 27 11:34:43 2014
@@ -96,9 +96,7 @@ public class DistanceStrategyTest extend
super.setUp();
if (strategy instanceof BBoxStrategy && random().nextBoolean()) {//disable indexing sometimes
BBoxStrategy bboxStrategy = (BBoxStrategy)strategy;
- final FieldType fieldType = new FieldType(bboxStrategy.getFieldType());
- fieldType.setIndexOptions(IndexOptions.NONE);
- bboxStrategy.setFieldType(fieldType);
+ bboxStrategy.setIndexOptions(fieldTypes, IndexOptions.NONE);
}
}
@@ -109,6 +107,7 @@ public class DistanceStrategyTest extend
@Test
public void testDistanceOrder() throws IOException {
+ System.out.println("TEST: strategy=" + strategy);
adoc("100", ctx.makePoint(2, 1));
adoc("101", ctx.makePoint(-1, 4));
adoc("103", (Shape)null);//test score for nothing
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java Thu Nov 27 11:34:43 2014
@@ -114,6 +114,7 @@ public class PortedSolr3Test extends Str
setupDocs();
//Try some edge cases
//NOTE: 2nd arg is distance in kilometers
+ System.out.println("STRAT=" + strategy);
checkHitsCircle(ctx.makePoint(1, 1), 175, 3, 5, 6, 7);
checkHitsCircle(ctx.makePoint(179.8, 0), 200, 2, 8, 9);
checkHitsCircle(ctx.makePoint(50, 89.8), 200, 2, 10, 11);//this goes over the north pole
@@ -169,10 +170,11 @@ public class PortedSolr3Test extends Str
//args.setDistPrecision(0.025);
Query query;
if (random().nextBoolean()) {
- query = strategy.makeQuery(args);
+ query = strategy.makeQuery(fieldTypes, args);
} else {
- query = new FilteredQuery(new MatchAllDocsQuery(),strategy.makeFilter(args));
+ query = new FilteredQuery(new MatchAllDocsQuery(),strategy.makeFilter(fieldTypes, args));
}
+ System.out.println("query=" + query);
SearchResults results = executeQuery(query, 100);
assertEquals(""+shape,assertNumFound,results.numFound);
if (assertIds != null) {
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java Thu Nov 27 11:34:43 2014
@@ -17,8 +17,13 @@ package org.apache.lucene.spatial;
* limitations under the License.
*/
-import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.shape.Shape;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.lucene.document.Document2;
+import org.apache.lucene.document.FieldTypes;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.spatial.bbox.BBoxStrategy;
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
import org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy;
@@ -29,18 +34,18 @@ import org.apache.lucene.spatial.query.S
import org.apache.lucene.spatial.query.SpatialOperation;
import org.apache.lucene.spatial.serialized.SerializedDVStrategy;
import org.apache.lucene.spatial.vector.PointVectorStrategy;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collection;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Shape;
public class QueryEqualsHashCodeTest extends LuceneTestCase {
private final SpatialContext ctx = SpatialContext.GEO;
@Test
- public void testEqualsHashCode() {
+ public void testEqualsHashCode() throws Exception {
final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx,10);
final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx,10);
@@ -56,19 +61,26 @@ public class QueryEqualsHashCodeTest ext
}
}
- private void testEqualsHashcode(final SpatialStrategy strategy) {
+ private void testEqualsHashcode(final SpatialStrategy strategy) throws Exception {
final SpatialArgs args1 = makeArgs1();
final SpatialArgs args2 = makeArgs2();
+ IndexWriterConfig iwConfig = new IndexWriterConfig(null);
+ Directory dir = newDirectory();
+ IndexWriter writer = new IndexWriter(dir, iwConfig);
+ Document2 doc = writer.newDocument();
+ strategy.addFields(doc, SpatialContext.GEO.makePoint(0, 0));
+ writer.addDocument(doc);
+ final FieldTypes fieldTypes = writer.getFieldTypes();
testEqualsHashcode(args1, args2, new ObjGenerator() {
@Override
public Object gen(SpatialArgs args) {
- return strategy.makeQuery(args);
+ return strategy.makeQuery(fieldTypes, args);
}
});
testEqualsHashcode(args1, args2, new ObjGenerator() {
@Override
public Object gen(SpatialArgs args) {
- return strategy.makeFilter(args);
+ return strategy.makeFilter(fieldTypes, args);
}
});
testEqualsHashcode(args1, args2, new ObjGenerator() {
@@ -77,6 +89,8 @@ public class QueryEqualsHashCodeTest ext
return strategy.makeDistanceValueSource(args.getShape().getCenter());
}
});
+ writer.close();
+ dir.close();
}
private void testEqualsHashcode(SpatialArgs args1, SpatialArgs args2, ObjGenerator generator) {
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java Thu Nov 27 11:34:43 2014
@@ -22,7 +22,7 @@ import java.io.IOException;
import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.IntField;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
@@ -107,32 +107,32 @@ public class SpatialExample extends Luce
IndexWriter indexWriter = new IndexWriter(directory, iwConfig);
//Spatial4j is x-y order for arguments
- indexWriter.addDocument(newSampleDocument(
+ indexWriter.addDocument(newSampleDocument(indexWriter,
2, ctx.makePoint(-80.93, 33.77)));
//Spatial4j has a WKT parser which is also "x y" order
- indexWriter.addDocument(newSampleDocument(
+ indexWriter.addDocument(newSampleDocument(indexWriter,
4, ctx.readShapeFromWkt("POINT(60.9289094 -50.7693246)")));
- indexWriter.addDocument(newSampleDocument(
+ indexWriter.addDocument(newSampleDocument(indexWriter,
20, ctx.makePoint(0.1,0.1), ctx.makePoint(0, 0)));
indexWriter.close();
}
- private Document newSampleDocument(int id, Shape... shapes) {
- Document doc = new Document();
- doc.add(new IntField("id", id, Field.Store.YES));
+ private Document2 newSampleDocument(IndexWriter indexWriter, int id, Shape... shapes) {
+ Document2 doc = indexWriter.newDocument();
+ FieldTypes fieldTypes = indexWriter.getFieldTypes();
+ fieldTypes.setMultiValued(strategy.getFieldName() + "_stored");
+ doc.addInt("id", id);
//Potentially more than one shape in this field is supported by some
// strategies; see the javadocs of the SpatialStrategy impl to see.
for (Shape shape : shapes) {
- for (Field f : strategy.createIndexableFields(shape)) {
- doc.add(f);
- }
+ strategy.addFields(doc, shape);
//store it too; the format is up to you
// (assume point in this example)
Point pt = (Point) shape;
- doc.add(new StoredField(strategy.getFieldName(), pt.getX()+" "+pt.getY()));
+ doc.addStored(strategy.getFieldName() + "_stored", pt.getX()+" "+pt.getY());
}
return doc;
@@ -140,6 +140,7 @@ public class SpatialExample extends Luce
private void search() throws Exception {
IndexReader indexReader = DirectoryReader.open(directory);
+ FieldTypes fieldTypes = indexReader.getFieldTypes();
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
Sort idSort = new Sort(new SortField("id", SortField.Type.INT));
@@ -149,13 +150,13 @@ public class SpatialExample extends Luce
//note: SpatialArgs can be parsed from a string
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,
ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(200, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
- Filter filter = strategy.makeFilter(args);
+ Filter filter = strategy.makeFilter(fieldTypes, args);
TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), filter, 10, idSort);
assertDocMatchedIds(indexSearcher, docs, 2);
//Now, lets get the distance for the 1st doc via computing from stored point value:
// (this computation is usually not redundant)
Document2 doc1 = indexSearcher.doc(docs.scoreDocs[0].doc);
- String doc1Str = doc1.getField(strategy.getFieldName()).stringValue();
+ String doc1Str = doc1.getString(strategy.getFieldName() + "_stored");
//assume doc1Str is "x y" as written in newSampleDocument()
int spaceIdx = doc1Str.indexOf(' ');
double x = Double.parseDouble(doc1Str.substring(0, spaceIdx));
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java Thu Nov 27 11:34:43 2014
@@ -27,6 +27,7 @@ import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldTypes;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.RandomIndexWriter;
@@ -58,6 +59,7 @@ public abstract class SpatialTestCase ex
protected RandomIndexWriter indexWriter;
private Directory directory;
protected IndexSearcher indexSearcher;
+ protected FieldTypes fieldTypes;
protected SpatialContext ctx;//subclass must initialize
@@ -77,6 +79,7 @@ public abstract class SpatialTestCase ex
indexWriter = new RandomIndexWriter(random,directory, newIndexWriterConfig(random));
indexReader = UninvertingReader.wrap(indexWriter.getReader(), uninvertMap);
indexSearcher = newSearcher(indexReader);
+ fieldTypes = indexWriter.getFieldTypes();
}
protected IndexWriterConfig newIndexWriterConfig(Random random) {
@@ -102,12 +105,12 @@ public abstract class SpatialTestCase ex
// ================================================= Helper Methods ================================================
- protected void addDocument(Document doc) throws IOException {
+ protected void addDocument(Document2 doc) throws IOException {
indexWriter.addDocument(doc);
}
- protected void addDocumentsAndCommit(List<Document> documents) throws IOException {
- for (Document document : documents) {
+ protected void addDocumentsAndCommit(List<Document2> documents) throws IOException {
+ for (Document2 document : documents) {
indexWriter.addDocument(document);
}
commit();
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java Thu Nov 27 11:34:43 2014
@@ -18,8 +18,19 @@ package org.apache.lucene.spatial;
* limitations under the License.
*/
-import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.shape.Shape;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField;
@@ -35,18 +46,8 @@ import org.apache.lucene.search.TopDocs;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialArgsParser;
import org.apache.lucene.spatial.query.SpatialOperation;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Logger;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Shape;
public abstract class StrategyTestCase extends SpatialTestCase {
@@ -78,32 +79,30 @@ public abstract class StrategyTestCase e
}
protected void getAddAndVerifyIndexedDocuments(String testDataFile) throws IOException {
- List<Document> testDocuments = getDocuments(testDataFile);
+ List<Document2> testDocuments = getDocuments(testDataFile);
addDocumentsAndCommit(testDocuments);
verifyDocumentsIndexed(testDocuments.size());
}
- protected List<Document> getDocuments(String testDataFile) throws IOException {
+ protected List<Document2> getDocuments(String testDataFile) throws IOException {
return getDocuments(getSampleData(testDataFile));
}
- protected List<Document> getDocuments(Iterator<SpatialTestData> sampleData) {
- List<Document> documents = new ArrayList<>();
+ protected List<Document2> getDocuments(Iterator<SpatialTestData> sampleData) {
+ List<Document2> documents = new ArrayList<>();
while (sampleData.hasNext()) {
SpatialTestData data = sampleData.next();
- Document document = new Document();
- document.add(new StringField("id", data.id, Field.Store.YES));
- document.add(new StringField("name", data.name, Field.Store.YES));
+ Document2 document = indexWriter.newDocument();
+ document.addAtom("id", data.id);
+ document.addAtom("name", data.name);
Shape shape = data.shape;
shape = convertShapeFromGetDocuments(shape);
if (shape != null) {
- for (Field f : strategy.createIndexableFields(shape)) {
- document.add(f);
+ strategy.addFields(document, shape);
+ if (storeShape) {//just for diagnostics
+ document.addStored(strategy.getFieldName() + "_stored", shape.toString());
}
- if (storeShape)//just for diagnostics
- document.add(new StoredField(strategy.getFieldName(), shape.toString()));
}
-
documents.add(document);
}
return documents;
@@ -140,9 +139,10 @@ public abstract class StrategyTestCase e
public void runTestQuery(SpatialMatchConcern concern, SpatialTestQuery q) {
String msg = q.toString(); //"Query: " + q.args.toString(ctx);
SearchResults got = executeQuery(makeQuery(q), Math.max(100, q.ids.size()+1));
+
if (storeShape && got.numFound > 0) {
//check stored value is there
- assertNotNull(got.results.get(0).document.get(strategy.getFieldName()));
+ assertNotNull(got.results.get(0).document.get(strategy.getFieldName() + "_stored"));
}
if (concern.orderIsImportant) {
Iterator<String> ids = q.ids.iterator();
@@ -184,7 +184,7 @@ public abstract class StrategyTestCase e
}
protected Query makeQuery(SpatialTestQuery q) {
- return strategy.makeQuery(q.args);
+ return strategy.makeQuery(fieldTypes, q.args);
}
protected void adoc(String id, String shapeStr) throws IOException, ParseException {
@@ -195,15 +195,14 @@ public abstract class StrategyTestCase e
addDocument(newDoc(id, shape));
}
- protected Document newDoc(String id, Shape shape) {
- Document doc = new Document();
- doc.add(new StringField("id", id, Field.Store.YES));
+ protected Document2 newDoc(String id, Shape shape) {
+ Document2 doc = indexWriter.newDocument();
+ doc.addAtom("id", id);
if (shape != null) {
- for (Field f : strategy.createIndexableFields(shape)) {
- doc.add(f);
+ strategy.addFields(doc, shape);
+ if (storeShape) {
+ doc.addStored(strategy.getFieldName() + "_stored", shape.toString());
}
- if (storeShape)
- doc.add(new StoredField(strategy.getFieldName(), shape.toString()));//not to be parsed; just for debug
}
return doc;
}
@@ -242,7 +241,7 @@ public abstract class StrategyTestCase e
(operation == SpatialOperation.Contains || operation == SpatialOperation.IsWithin));
adoc("0", indexedShape);
commit();
- Query query = strategy.makeQuery(new SpatialArgs(operation, queryShape));
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(operation, queryShape));
SearchResults got = executeQuery(query, 1);
assert got.numFound <= 1 : "unclean test env";
if ((got.numFound == 1) != match)
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java Thu Nov 27 11:34:43 2014
@@ -111,10 +111,9 @@ public class TestBBoxStrategy extends Ra
//test we can disable docValues for predicate tests
if (random().nextBoolean()) {
BBoxStrategy bboxStrategy = (BBoxStrategy) strategy;
- FieldType fieldType = new FieldType(bboxStrategy.getFieldType());
- fieldType.setDocValuesType(DocValuesType.NONE);
- bboxStrategy.setFieldType(fieldType);
+ bboxStrategy.setDocValuesType(fieldTypes, DocValuesType.NONE);
}
+
for (SpatialOperation operation : SpatialOperation.values()) {
if (operation == SpatialOperation.Overlaps)
continue;//unsupported
@@ -189,7 +188,7 @@ public class TestBBoxStrategy extends Ra
adoc("0", indexedShape);
commit();
- Query query = strategy.makeQuery(new SpatialArgs(operation, queryShape));
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(operation, queryShape));
SearchResults got = executeQuery(query, 1);
assert got.numFound <= 1 : "unclean test env";
if ((got.numFound == 1) != match)
@@ -292,10 +291,9 @@ public class TestBBoxStrategy extends Ra
setupGeo();
//test we can disable indexed for this test
BBoxStrategy bboxStrategy = (BBoxStrategy) strategy;
+ //test we can disable indexed for this test
if (random().nextBoolean()) {
- FieldType fieldType = new FieldType(bboxStrategy.getFieldType());
- fieldType.setIndexOptions(IndexOptions.NONE);
- bboxStrategy.setFieldType(fieldType);
+ bboxStrategy.setIndexOptions(fieldTypes, IndexOptions.NONE);
}
adoc("100", ctx.makeRectangle(0, 20, 40, 80));
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/JtsPolygonTest.java Thu Nov 27 11:34:43 2014
@@ -17,12 +17,13 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import com.spatial4j.core.context.SpatialContextFactory;
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Shape;
+import java.text.ParseException;
+import java.util.HashMap;
+
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
@@ -34,9 +35,9 @@ import org.apache.lucene.spatial.prefix.
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.junit.Test;
-
-import java.text.ParseException;
-import java.util.HashMap;
+import com.spatial4j.core.context.SpatialContextFactory;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Shape;
public class JtsPolygonTest extends StrategyTestCase {
@@ -67,7 +68,7 @@ public class JtsPolygonTest extends Stra
"-93.16315546122038 45.23742639412364," +
"-93.18100824442227 45.25676372469945))",
LUCENE_4464_distErrPct);
- SearchResults got = executeQuery(strategy.makeQuery(args), 100);
+ SearchResults got = executeQuery(strategy.makeQuery(fieldTypes, args), 100);
assertEquals(1, got.numFound);
assertEquals("poly2", got.results.get(0).document.get("id"));
//did not find poly 1 !
@@ -91,19 +92,15 @@ public class JtsPolygonTest extends Stra
SpatialPrefixTree trie = new QuadPrefixTree(ctx, 12);
TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
- Document doc = new Document();
- doc.add(new TextField("id", "1", Store.YES));
-
- Field[] fields = strategy.createIndexableFields(area, 0.025);
- for (Field field : fields) {
- doc.add(field);
- }
+ Document2 doc = indexWriter.newDocument();
+ doc.addAtom("id", "1");
+ strategy.addFields(doc, area, 0.025);
addDocument(doc);
Point upperleft = ctx.makePoint(-122.88, 48.54);
Point lowerright = ctx.makePoint(-122.82, 48.62);
- Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
commit();
TopDocs search = indexSearcher.search(query, 10);
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java Thu Nov 27 11:34:43 2014
@@ -17,15 +17,19 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import com.carrotsearch.randomizedtesting.annotations.Repeat;
-import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.context.SpatialContextFactory;
-import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.Rectangle;
-import com.spatial4j.core.shape.Shape;
-import com.spatial4j.core.shape.ShapeCollection;
-import com.spatial4j.core.shape.SpatialRelation;
-import com.spatial4j.core.shape.impl.RectangleImpl;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.document.Document2;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField;
@@ -40,18 +44,15 @@ import org.apache.lucene.spatial.prefix.
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.junit.Test;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.carrotsearch.randomizedtesting.annotations.Repeat;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.context.SpatialContextFactory;
+import com.spatial4j.core.shape.Point;
+import com.spatial4j.core.shape.Rectangle;
+import com.spatial4j.core.shape.Shape;
+import com.spatial4j.core.shape.ShapeCollection;
+import com.spatial4j.core.shape.SpatialRelation;
+import com.spatial4j.core.shape.impl.RectangleImpl;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomInt;
@@ -144,7 +145,7 @@ public class RandomSpatialOpFuzzyPrefixT
setupQuadGrid(3);
adoc("0", new ShapePair(ctx.makeRectangle(0, 33, -128, 128), ctx.makeRectangle(33, 128, -128, 128), true));
commit();
- Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Contains,
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(SpatialOperation.Contains,
ctx.makeRectangle(0, 128, -16, 128)));
SearchResults searchResults = executeQuery(query, 1);
assertEquals(1, searchResults.numFound);
@@ -157,7 +158,7 @@ public class RandomSpatialOpFuzzyPrefixT
adoc("0", new ShapePair(ctx.makeRectangle(0, 10, -120, -100), ctx.makeRectangle(220, 240, 110, 125), false));
commit();
//query surrounds only the second part of the indexed shape
- Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.IsWithin,
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(SpatialOperation.IsWithin,
ctx.makeRectangle(210, 245, 105, 128)));
SearchResults searchResults = executeQuery(query, 1);
//we shouldn't find it because it's not completely within
@@ -176,13 +177,13 @@ public class RandomSpatialOpFuzzyPrefixT
//query does NOT contain it; both indexed cells are leaves to the query, and
// when expanded to the full grid cells, the top one's top row is disjoint
// from the query and thus not a match.
- assertTrue(executeQuery(strategy.makeQuery(
+ assertTrue(executeQuery(strategy.makeQuery(fieldTypes,
new SpatialArgs(SpatialOperation.IsWithin, ctx.makeRectangle(38, 192, -72, 56))
), 1).numFound==0);//no-match
//this time the rect is a little bigger and is considered a match. It's a
// an acceptable false-positive because of the grid approximation.
- assertTrue(executeQuery(strategy.makeQuery(
+ assertTrue(executeQuery(strategy.makeQuery(fieldTypes,
new SpatialArgs(SpatialOperation.IsWithin, ctx.makeRectangle(38, 192, -72, 80))
), 1).numFound==1);//match
}
@@ -200,9 +201,10 @@ public class RandomSpatialOpFuzzyPrefixT
//Override so we can index parts of a pair separately, resulting in the detailLevel
// being independent for each shape vs the whole thing
@Override
- protected Document newDoc(String id, Shape shape) {
- Document doc = new Document();
- doc.add(new StringField("id", id, Field.Store.YES));
+ protected Document2 newDoc(String id, Shape shape) {
+ Document2 doc = indexWriter.newDocument();
+ fieldTypes.setMultiValued(strategy.getFieldName());
+ doc.addAtom("id", id);
if (shape != null) {
Collection<Shape> shapes;
if (shape instanceof ShapePair) {
@@ -213,12 +215,10 @@ public class RandomSpatialOpFuzzyPrefixT
shapes = Collections.singleton(shape);
}
for (Shape shapei : shapes) {
- for (Field f : strategy.createIndexableFields(shapei)) {
- doc.add(f);
- }
+ strategy.addFields(doc, shapei);
}
if (storeShape)//just for diagnostics
- doc.add(new StoredField(strategy.getFieldName(), shape.toString()));
+ doc.addStored(strategy.getFieldName() + "_stored", shape.toString());
}
return doc;
}
@@ -226,7 +226,7 @@ public class RandomSpatialOpFuzzyPrefixT
private void doTest(final SpatialOperation operation) throws IOException {
//first show that when there's no data, a query will result in no results
{
- Query query = strategy.makeQuery(new SpatialArgs(operation, randomRectangle()));
+ Query query = strategy.makeQuery(fieldTypes, new SpatialArgs(operation, randomRectangle()));
SearchResults searchResults = executeQuery(query, 1);
assertEquals(0, searchResults.numFound);
}
@@ -342,7 +342,7 @@ public class RandomSpatialOpFuzzyPrefixT
SpatialArgs args = new SpatialArgs(operation, queryShape);
if (queryShape instanceof ShapePair)
args.setDistErrPct(0.0);//a hack; we want to be more detailed than gridSnap(queryShape)
- Query query = strategy.makeQuery(args);
+ Query query = strategy.makeQuery(fieldTypes, args);
SearchResults got = executeQuery(query, 100);
Set<String> remainingExpectedIds = new LinkedHashSet<>(expectedIds);
for (SearchResult result : got.results) {
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java Thu Nov 27 11:34:43 2014
@@ -40,13 +40,6 @@ public abstract class RandomSpatialOpStr
//Note: this is partially redundant with StrategyTestCase.runTestQuery & testOperation
protected void testOperationRandomShapes(final SpatialOperation operation) throws IOException {
- //first show that when there's no data, a query will result in no results
- {
- Query query = strategy.makeQuery(new SpatialArgs(operation, randomQueryShape()));
- SearchResults searchResults = executeQuery(query, 1);
- assertEquals(0, searchResults.numFound);
- }
-
final int numIndexedShapes = randomIntBetween(1, 6);
List<Shape> indexedShapes = new ArrayList<>(numIndexedShapes);
for (int i = 0; i < numIndexedShapes; i++) {
@@ -64,6 +57,7 @@ public abstract class RandomSpatialOpStr
protected void testOperation(final SpatialOperation operation,
List<Shape> indexedShapes, List<Shape> queryShapes, boolean havoc) throws IOException {
+
//Main index loop:
for (int i = 0; i < indexedShapes.size(); i++) {
Shape shape = indexedShapes.get(i);
@@ -106,7 +100,7 @@ public abstract class RandomSpatialOpStr
//Search and verify results
SpatialArgs args = new SpatialArgs(operation, queryShape);
- Query query = strategy.makeQuery(args);
+ Query query = strategy.makeQuery(fieldTypes, args);
SearchResults got = executeQuery(query, 100);
Set<String> remainingExpectedIds = new LinkedHashSet<>(expectedIds);
for (SearchResult result : got.results) {
Modified: lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java (original)
+++ lucene/dev/branches/lucene6005/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java Thu Nov 27 11:34:43 2014
@@ -107,7 +107,7 @@ public class TestRecursivePrefixTreeStra
}
private void checkHits(SpatialArgs args, int assertNumFound, int[] assertIds) {
- SearchResults got = executeQuery(strategy.makeQuery(args), 100);
+ SearchResults got = executeQuery(strategy.makeQuery(fieldTypes, args), 100);
assertEquals("" + args, assertNumFound, got.numFound);
if (assertIds != null) {
Set<Integer> gotIds = new HashSet<>();