LUCENE-4192 remove spatial isPolyField and createField

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1360687 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2012-07-12 14:06:30 +00:00
parent 2c7e1721b7
commit e43973683e
8 changed files with 23 additions and 53 deletions

View File

@ -59,11 +59,6 @@ public abstract class SpatialStrategy {
return ctx; return ctx;
} }
/** Corresponds with Solr's FieldType.isPolyField(). */
public boolean isPolyField() {
return false;
}
/** /**
* The name of the field or the prefix of them if there are multiple * The name of the field or the prefix of them if there are multiple
* fields needed internally. * fields needed internally.
@ -74,26 +69,19 @@ public abstract class SpatialStrategy {
} }
/** /**
* Corresponds with Solr's FieldType.createField(). * Returns the IndexableField(s) from the <code>shape</code> that are to be
* * added to the {@link org.apache.lucene.document.Document}. These fields
* This may return a null field if it does not want to make anything. * are expected to be marked as indexed and not stored.
* This is reasonable behavior if 'ignoreIncompatibleGeometry=true' and the
* geometry is incompatible
*/
public abstract IndexableField createField(Shape shape);
/**
* Corresponds with Solr's FieldType.createFields().
* <p/> * <p/>
* Note: If you want to <i>store</i> the shape as a string for retrieval in search * Note: If you want to <i>store</i> the shape as a string for retrieval in
* results, you could add it like this: * search results, you could add it like this:
* <pre>document.add(new StoredField(fieldName,ctx.toString(shape)));</pre> * <pre>document.add(new StoredField(fieldName,ctx.toString(shape)));</pre>
* The particular string representation used doesn't matter to the Strategy since it * The particular string representation used doesn't matter to the Strategy
* doesn't use it. * since it doesn't use it.
*
* @return Not null nor will it have null elements.
*/ */
public IndexableField[] createFields(Shape shape) { public abstract IndexableField[] createIndexableFields(Shape shape);
return new IndexableField[]{createField(shape)};
}
/** /**
* The value source yields a number that is proportional to the distance between the query shape and indexed data. * The value source yields a number that is proportional to the distance between the query shape and indexed data.

View File

@ -92,7 +92,7 @@ public class BBoxStrategy extends SpatialStrategy {
//--------------------------------- //---------------------------------
@Override @Override
public IndexableField[] createFields(Shape shape) { public IndexableField[] createIndexableFields(Shape shape) {
Rectangle bbox = shape.getBoundingBox(); Rectangle bbox = shape.getBoundingBox();
FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED); FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
doubleFieldType.setNumericPrecisionStep(precisionStep); doubleFieldType.setNumericPrecisionStep(precisionStep);
@ -105,16 +105,6 @@ public class BBoxStrategy extends SpatialStrategy {
return fields; return fields;
} }
@Override
public IndexableField createField(Shape shape) {
throw new UnsupportedOperationException("BBOX is poly field");
}
@Override
public boolean isPolyField() {
return true;
}
//--------------------------------- //---------------------------------
// Query Builder // Query Builder
//--------------------------------- //---------------------------------

View File

@ -62,7 +62,7 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
} }
@Override @Override
public IndexableField createField(Shape shape) { public IndexableField[] createIndexableFields(Shape shape) {
int detailLevel = grid.getMaxLevelForPrecision(shape,distErrPct); int detailLevel = grid.getMaxLevelForPrecision(shape,distErrPct);
List<Node> cells = grid.getNodes(shape, detailLevel, true);//true=intermediates cells List<Node> cells = grid.getNodes(shape, detailLevel, true);//true=intermediates cells
//If shape isn't a point, add a full-resolution center-point so that //If shape isn't a point, add a full-resolution center-point so that
@ -77,7 +77,8 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
//TODO is CellTokenStream supposed to be re-used somehow? see Uwe's comments: //TODO is CellTokenStream supposed to be re-used somehow? see Uwe's comments:
// http://code.google.com/p/lucene-spatial-playground/issues/detail?id=4 // http://code.google.com/p/lucene-spatial-playground/issues/detail?id=4
return new Field(getFieldName(),new CellTokenStream(cells.iterator()), FIELD_TYPE); Field field = new Field(getFieldName(), new CellTokenStream(cells.iterator()), FIELD_TYPE);
return new IndexableField[]{field};
} }
/* Indexed, tokenized, not stored. */ /* Indexed, tokenized, not stored. */

View File

@ -77,12 +77,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
} }
@Override @Override
public boolean isPolyField() { public IndexableField[] createIndexableFields(Shape shape) {
return true;
}
@Override
public IndexableField[] createFields(Shape shape) {
if( shape instanceof Point ) { if( shape instanceof Point ) {
Point point = (Point)shape; Point point = (Point)shape;
FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED); FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
@ -98,11 +93,6 @@ public class TwoDoublesStrategy extends SpatialStrategy {
return new IndexableField[0]; // nothing (solr does not support null) return new IndexableField[0]; // nothing (solr does not support null)
} }
@Override
public IndexableField createField(Shape shape) {
throw new UnsupportedOperationException("Point is poly field");
}
@Override @Override
public ValueSource makeValueSource(SpatialArgs args) { public ValueSource makeValueSource(SpatialArgs args) {
Point p = args.getShape().getCenter(); Point p = args.getShape().getCenter();

View File

@ -194,7 +194,7 @@ public class PortedSolr3Test extends StrategyTestCase {
private Document newDoc(String id, Shape shape) { private Document newDoc(String id, Shape shape) {
Document doc = new Document(); Document doc = new Document();
doc.add(new StringField("id", id, Field.Store.YES)); doc.add(new StringField("id", id, Field.Store.YES));
for (IndexableField f : strategy.createFields(shape)) { for (IndexableField f : strategy.createIndexableFields(shape)) {
doc.add(f); doc.add(f);
} }
if (storeShape) if (storeShape)

View File

@ -85,11 +85,9 @@ public abstract class StrategyTestCase extends SpatialTestCase {
document.add(new StringField("id", data.id, Field.Store.YES)); document.add(new StringField("id", data.id, Field.Store.YES));
document.add(new StringField("name", data.name, Field.Store.YES)); document.add(new StringField("name", data.name, Field.Store.YES));
Shape shape = ctx.readShape(data.shape); Shape shape = ctx.readShape(data.shape);
for (IndexableField f : strategy.createFields(shape)) { for (IndexableField f : strategy.createIndexableFields(shape)) {
if( f != null ) { // null if incompatibleGeometry && ignore
document.add(f); document.add(f);
} }
}
if (storeShape) if (storeShape)
document.add(new StoredField(strategy.getFieldName(), ctx.toString(shape))); document.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));

View File

@ -154,7 +154,7 @@ public class TestRecursivePrefixTreeStrategy extends StrategyTestCase {
private Document newDoc(String id, Shape shape) { private Document newDoc(String id, Shape shape) {
Document doc = new Document(); Document doc = new Document();
doc.add(new StringField("id", id, Field.Store.YES)); doc.add(new StringField("id", id, Field.Store.YES));
for (IndexableField f : strategy.createFields(shape)) { for (IndexableField f : strategy.createIndexableFields(shape)) {
doc.add(f); doc.add(f);
} }
if (storeShape) if (storeShape)

View File

@ -25,6 +25,7 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StoredField;
import org.apache.lucene.document.StringField; import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.spatial.SpatialTestCase; import org.apache.lucene.spatial.SpatialTestCase;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree; import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgsParser; import org.apache.lucene.spatial.query.SpatialArgsParser;
@ -45,7 +46,9 @@ public class TestTermQueryPrefixGridStrategy extends SpatialTestCase {
Document losAngeles = new Document(); Document losAngeles = new Document();
losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES)); losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
losAngeles.add(prefixGridStrategy.createField(point)); for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) {
losAngeles.add(field);
}
losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), ctx.toString(point))); losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), ctx.toString(point)));
addDocumentsAndCommit(Arrays.asList(losAngeles)); addDocumentsAndCommit(Arrays.asList(losAngeles));