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;
}
/** 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
* fields needed internally.
@ -74,26 +69,19 @@ public abstract class SpatialStrategy {
}
/**
* Corresponds with Solr's FieldType.createField().
*
* This may return a null field if it does not want to make anything.
* This is reasonable behavior if 'ignoreIncompatibleGeometry=true' and the
* geometry is incompatible
*/
public abstract IndexableField createField(Shape shape);
/**
* Corresponds with Solr's FieldType.createFields().
* Returns the IndexableField(s) from the <code>shape</code> that are to be
* added to the {@link org.apache.lucene.document.Document}. These fields
* are expected to be marked as indexed and not stored.
* <p/>
* Note: If you want to <i>store</i> the shape as a string for retrieval in search
* results, you could add it like this:
* Note: If you want to <i>store</i> the shape as a string for retrieval in
* search results, you could add it like this:
* <pre>document.add(new StoredField(fieldName,ctx.toString(shape)));</pre>
* The particular string representation used doesn't matter to the Strategy since it
* doesn't use it.
* The particular string representation used doesn't matter to the Strategy
* since it doesn't use it.
*
* @return Not null nor will it have null elements.
*/
public IndexableField[] createFields(Shape shape) {
return new IndexableField[]{createField(shape)};
}
public abstract IndexableField[] createIndexableFields(Shape shape);
/**
* 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
public IndexableField[] createFields(Shape shape) {
public IndexableField[] createIndexableFields(Shape shape) {
Rectangle bbox = shape.getBoundingBox();
FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED);
doubleFieldType.setNumericPrecisionStep(precisionStep);
@ -105,16 +105,6 @@ public class BBoxStrategy extends SpatialStrategy {
return fields;
}
@Override
public IndexableField createField(Shape shape) {
throw new UnsupportedOperationException("BBOX is poly field");
}
@Override
public boolean isPolyField() {
return true;
}
//---------------------------------
// Query Builder
//---------------------------------

View File

@ -62,7 +62,7 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
}
@Override
public IndexableField createField(Shape shape) {
public IndexableField[] createIndexableFields(Shape shape) {
int detailLevel = grid.getMaxLevelForPrecision(shape,distErrPct);
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
@ -77,7 +77,8 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {
//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
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. */

View File

@ -77,12 +77,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
}
@Override
public boolean isPolyField() {
return true;
}
@Override
public IndexableField[] createFields(Shape shape) {
public IndexableField[] createIndexableFields(Shape shape) {
if( shape instanceof Point ) {
Point point = (Point)shape;
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)
}
@Override
public IndexableField createField(Shape shape) {
throw new UnsupportedOperationException("Point is poly field");
}
@Override
public ValueSource makeValueSource(SpatialArgs args) {
Point p = args.getShape().getCenter();

View File

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

View File

@ -85,10 +85,8 @@ public abstract class StrategyTestCase extends SpatialTestCase {
document.add(new StringField("id", data.id, Field.Store.YES));
document.add(new StringField("name", data.name, Field.Store.YES));
Shape shape = ctx.readShape(data.shape);
for (IndexableField f : strategy.createFields(shape)) {
if( f != null ) { // null if incompatibleGeometry && ignore
document.add(f);
}
for (IndexableField f : strategy.createIndexableFields(shape)) {
document.add(f);
}
if (storeShape)
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) {
Document doc = new Document();
doc.add(new StringField("id", id, Field.Store.YES));
for (IndexableField f : strategy.createFields(shape)) {
for (IndexableField f : strategy.createIndexableFields(shape)) {
doc.add(f);
}
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.StoredField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.spatial.SpatialTestCase;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgsParser;
@ -45,7 +46,9 @@ public class TestTermQueryPrefixGridStrategy extends SpatialTestCase {
Document losAngeles = new Document();
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)));
addDocumentsAndCommit(Arrays.asList(losAngeles));