You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2009/12/24 18:42:49 UTC

svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Author: yonik
Date: Thu Dec 24 17:42:48 2009
New Revision: 893792

URL: http://svn.apache.org/viewvc?rev=893792&view=rev
Log:
SOLR-1131: first pass at fixing support for subFieldSuffix (index + search)

Modified:
    lucene/solr/trunk/example/solr/conf/schema.xml
    lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java

Modified: lucene/solr/trunk/example/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/schema.xml?rev=893792&r1=893791&r2=893792&view=diff
==============================================================================
--- lucene/solr/trunk/example/solr/conf/schema.xml (original)
+++ lucene/solr/trunk/example/solr/conf/schema.xml Thu Dec 24 17:42:48 2009
@@ -407,7 +407,7 @@
       The subFields are an implementation detail of the fieldType, and end
       users normally should not need to know about them.
      -->
-    <fieldType name="location" class="solr.PointType" dimension="2" subFieldType="double"/>
+    <fieldType name="location" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
 
  </types>
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java?rev=893792&r1=893791&r2=893792&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java Thu Dec 24 17:42:48 2009
@@ -55,7 +55,7 @@
   protected FieldType subType;
   public static final String SUB_FIELD_SUFFIX = "subFieldSuffix";
   public static final String SUB_FIELD_TYPE = "subFieldType";
-  private String suffix;//need to keep this around between init and inform, since dynamic fields aren't created until before inform
+  protected String suffix;
   protected int dynFieldProps;
 
   public int getDimension() {
@@ -76,6 +76,7 @@
     if (subFT != null) {
       args.remove(SUB_FIELD_TYPE);
       subType = schema.getFieldTypeByName(subFT.trim());
+      suffix = POLY_FIELD_SEPARATOR + subType.typeName;      
     } else if (subSuffix != null) {
       args.remove(SUB_FIELD_SUFFIX);
       suffix = subSuffix;
@@ -90,18 +91,9 @@
 
   public void inform(IndexSchema schema) {
     //Can't do this until here b/c the Dynamic Fields are not initialized until here.
-    if (suffix != null){
-      SchemaField sf = schema.getField(suffix);
-      subType = sf.getType();//this means it is already registered
-      dynFieldProps = sf.getProperties(); 
-    }
-    else if (subType != null) {
+    if (subType != null) {
       SchemaField proto = registerPolyFieldDynamicPrototype(schema, subType);
       dynFieldProps = proto.getProperties();
-    } else {
-      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "The field type: " + typeName
-              + " must specify the " +
-      SUB_FIELD_TYPE + " attribute or the " + SUB_FIELD_SUFFIX + " attribute.");
     }
   }
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java?rev=893792&r1=893791&r2=893792&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java Thu Dec 24 17:42:48 2009
@@ -242,72 +242,6 @@
   }
 
 
-
-  /**
-   * Create multiple fields from a single field and multiple values.  Fields are named as SchemaField.getName() + {@link #POLY_FIELD_SEPARATOR} + i, where
-   * i starts at 0.
-   * <p/>
-   * If the field is stored, then an extra field gets created that contains the storageVal.  It is this field that also
-   *
-   * @param field The {@link org.apache.solr.schema.SchemaField}
-   * @param props The properties to use
-   * @param delegatedType An optional type to use.  If null, then field.getType() is used.  Useful for poly fields.
-   * @param storageVal If the field stores, then this value will be used for the stored field
-   * @param boost The boost to apply to all fields
-   * @param externalVals The values to use
-   * @return The fields
-   */
-  protected Fieldable[] createFields(SchemaField field, int props,
-                                 FieldType delegatedType, String storageVal,
-                                 float boost, String ... externalVals) {
-    int n = field.indexed() ? externalVals.length : 0;
-    n += field.stored() ? 1 : 0;
-    if (delegatedType == null) { //if the type isn't being overriden, then just use the base one
-      delegatedType = field.getType();
-    }
-    Field[] results = new Field[n];
-    //Field.Store.NO,Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO, true, true
-
-    if (externalVals.length > 0) {
-      if (field.indexed()) {
-        String name = field.getName() + "_";
-        String suffix = POLY_FIELD_SEPARATOR + delegatedType.typeName;
-
-        int len = name.length();
-        StringBuilder bldr = new StringBuilder(len + 3 + suffix.length());//should be enough buffer to handle most values of j.
-        bldr.append(name);
-        for (int j = 0; j < externalVals.length; j++) {
-          //SchemaField is final, as is name, so we need to recreate each time
-          //put the counter before the separator, b/c dynamic fields can't be asterisks on both the front and the end of the String
-          bldr.append(j).append(suffix);
-          SchemaField sf = SchemaField.create(bldr.toString(),
-                  delegatedType, props, null);
-                  //schema.getDynamicField(name  + "_" + j + POLY_FIELD_SEPARATOR + delegatedType.typeName);
-                  /**/
-          //new SchemaField(name, ft, p, defaultValue )
-          //QUESTION: should we allow for vectors, etc?  Not sure that it makes sense
-          results[j] = delegatedType.createField(sf, externalVals[j], boost);
-          bldr.setLength(len);//cut the builder back to just the length of the prefix, but keep the capacity
-        }
-      }
-      Field.TermVector fieldTermVec = getFieldTermVec(field, storageVal);
-      if (field.stored() || fieldTermVec.equals(Field.TermVector.YES)
-              || fieldTermVec.equals(Field.TermVector.WITH_OFFSETS)
-              || fieldTermVec.equals(Field.TermVector.WITH_POSITIONS)
-              || fieldTermVec.equals(Field.TermVector.WITH_POSITIONS_OFFSETS)
-      ) {
-
-          //QUESTION: should we allow for vectors, etc?  Not sure that it makes sense
-        results[results.length - 1] = createField(field.getName(), storageVal, getFieldStore(field, storageVal),
-                Field.Index.NO,
-                fieldTermVec, field.omitNorms(), field.omitTf(), boost);
-         
-      }
-
-    }
-    return results;
-  }
-
   /**
    * Create the field from native Lucene parts.  Mostly intended for use by FieldTypes outputing multiple
    * Fields per SchemaField

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java?rev=893792&r1=893791&r2=893792&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java Thu Dec 24 17:42:48 2009
@@ -54,7 +54,7 @@
   public static final String DIMENSION = "dimension";
 
   protected IndexSchema schema;   // needed for retrieving SchemaFields
-
+  protected String[] suffixes;
 
   @Override
   protected void init(IndexSchema schema, Map<String, String> args) {
@@ -68,6 +68,15 @@
     this.schema = schema;
     super.init(schema, args);
 
+    // cache suffixes
+    suffixes = new String[dimension];
+    for (int i=0; i<dimension; i++) {
+      suffixes[i] = "_" + i + suffix;
+    }
+  }
+
+  protected SchemaField subField(SchemaField base, int i) {
+    return schema.getField(base.getName() + suffixes[i]);
   }
 
 
@@ -79,7 +88,24 @@
   @Override
   public Fieldable[] createFields(SchemaField field, String externalVal, float boost) {
     String[] point = DistanceUtils.parsePoint(null, externalVal, dimension);
-    return createFields(field, dynFieldProps, subType, externalVal, boost, point);
+
+    // TODO: this doesn't currently support polyFields as sub-field types
+    Fieldable[] f = new Fieldable[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ];
+
+    if (field.indexed()) {
+      for (int i=0; i<dimension; i++) {
+        f[i] = subField(field, i).createField(point[i], boost);
+      }
+    }
+
+    if (field.stored()) {
+      String storedVal = externalVal;  // normalize or not?
+      f[f.length - 1] = createField(field.getName(), storedVal,
+                getFieldStore(field, storedVal), Field.Index.NO, Field.TermVector.NO,
+                false, false, boost);
+    }
+    
+    return f;
   }
 
   @Override
@@ -119,50 +145,25 @@
     String[] p1 = DistanceUtils.parsePoint(null, part1, dimension);
     String[] p2 = DistanceUtils.parsePoint(null, part2, dimension);
     BooleanQuery result = new BooleanQuery(true);
-    String name = field.getName() + "_";
-    String suffix = POLY_FIELD_SEPARATOR + subType.typeName;
-    int len = name.length();
-    StringBuilder bldr = new StringBuilder(len + 3 + suffix.length());//should be enough buffer to handle most values of j.
-    bldr.append(name);
     for (int i = 0; i < dimension; i++) {
-      bldr.append(i).append(suffix);
-      SchemaField subSF = schema.getField(bldr.toString());
+      SchemaField subSF = subField(field, i);
       // points must currently be ordered... should we support specifying any two opposite corner points?
-
-      /*new TermRangeQuery(
-     field.getName() + i + POLY_FIELD_SEPARATOR + subType.typeName,
-     subType.toInternal(p1[i]),
-     subType.toInternal(p2[i]),
-     minInclusive, maxInclusive);*/
-      result.add(subType.getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
-      bldr.setLength(len);
+      result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
     }
     return result;
   }
 
   @Override
   public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
-    Query result = null;
-
     String[] p1 = DistanceUtils.parsePoint(null, externalVal, dimension);
     //TODO: should we assert that p1.length == dimension?
     BooleanQuery bq = new BooleanQuery(true);
-    String name = field.getName() + "_";
-    String suffix = POLY_FIELD_SEPARATOR + subType.typeName;
-    int len = name.length();
-    StringBuilder bldr = new StringBuilder(len + 3 + suffix.length());//should be enough buffer to handle most values of j.
-    bldr.append(name);
     for (int i = 0; i < dimension; i++) {
-      bldr.append(i).append(suffix);
-      SchemaField sf1 = schema.getField(bldr.toString());
-      Query tq = subType.getFieldQuery(parser, sf1, p1[i]);
-      //new TermQuery(new Term(bldr.toString(), subType.toInternal(p1[i])));
+      SchemaField sf = subField(field, i);
+      Query tq = sf.getType().getFieldQuery(parser, sf, p1[i]);
       bq.add(tq, BooleanClause.Occur.MUST);
-      bldr.setLength(len);
     }
-    result = bq;
-
-    return result;
+    return bq;
   }
 
   class PointTypeValueSource extends MultiValueSource {
@@ -272,5 +273,3 @@
   }
 
 }
-
-



Re: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Thu, Dec 24, 2009 at 1:28 PM, Grant Ingersoll <gs...@apache.org> wrote:
> On Dec 24, 2009, at 12:42 PM, yonik@apache.org wrote:
>> -    <fieldType name="location" class="solr.PointType" dimension="2" subFieldType="double"/>
>> +    <fieldType name="location" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
>>
>>  </types>
>
> Shouldn't we demo both?

There are tradeoffs to including all variations of something (that
being schema bloat).  These two variants do the exact same thing for
the end user (since the only difference is sub-field naming), so we
should pick one or the other IMO.  That's what most people will end up
using.  We could include the other variant commented out, but I think
that's overkill too given that we listed an example of each in the
comment for "location".

-Yonik
http://www.lucidimagination.com

Re: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Grant Ingersoll <gs...@apache.org>.
On Dec 24, 2009, at 12:42 PM, yonik@apache.org wrote:

> Author: yonik
> Date: Thu Dec 24 17:42:48 2009
> New Revision: 893792
> 
> URL: http://svn.apache.org/viewvc?rev=893792&view=rev
> Log:
> SOLR-1131: first pass at fixing support for subFieldSuffix (index + search)
> 
> Modified:
>    lucene/solr/trunk/example/solr/conf/schema.xml
>    lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java
>    lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
>    lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java
> 
> Modified: lucene/solr/trunk/example/solr/conf/schema.xml
> URL: http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/schema.xml?rev=893792&r1=893791&r2=893792&view=diff
> ==============================================================================
> --- lucene/solr/trunk/example/solr/conf/schema.xml (original)
> +++ lucene/solr/trunk/example/solr/conf/schema.xml Thu Dec 24 17:42:48 2009
> @@ -407,7 +407,7 @@
>       The subFields are an implementation detail of the fieldType, and end
>       users normally should not need to know about them.
>      -->
> -    <fieldType name="location" class="solr.PointType" dimension="2" subFieldType="double"/>
> +    <fieldType name="location" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
> 
>  </types>

Shouldn't we demo both?

> 
> 
> Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java
> URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java?rev=893792&r1=893791&r2=893792&view=diff
> ==============================================================================
> --- lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java (original)
> +++ lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java Thu Dec 24 17:42:48 2009
> @@ -55,7 +55,7 @@
>   protected FieldType subType;
>   public static final String SUB_FIELD_SUFFIX = "subFieldSuffix";
>   public static final String SUB_FIELD_TYPE = "subFieldType";
> -  private String suffix;//need to keep this around between init and inform, since dynamic fields aren't created until before inform
> +  protected String suffix;
>   protected int dynFieldProps;
> 
>   public int getDimension() {
> @@ -76,6 +76,7 @@
>     if (subFT != null) {
>       args.remove(SUB_FIELD_TYPE);
>       subType = schema.getFieldTypeByName(subFT.trim());
> +      suffix = POLY_FIELD_SEPARATOR + subType.typeName;      
>     } else if (subSuffix != null) {
>       args.remove(SUB_FIELD_SUFFIX);
>       suffix = subSuffix;
> @@ -90,18 +91,9 @@
> 
>   public void inform(IndexSchema schema) {
>     //Can't do this until here b/c the Dynamic Fields are not initialized until here.
> -    if (suffix != null){
> -      SchemaField sf = schema.getField(suffix);
> -      subType = sf.getType();//this means it is already registered
> -      dynFieldProps = sf.getProperties(); 
> -    }
> -    else if (subType != null) {
> +    if (subType != null) {
>       SchemaField proto = registerPolyFieldDynamicPrototype(schema, subType);
>       dynFieldProps = proto.getProperties();
> -    } else {
> -      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "The field type: " + typeName
> -              + " must specify the " +
> -      SUB_FIELD_TYPE + " attribute or the " + SUB_FIELD_SUFFIX + " attribute.");
>     }
>   }
> 


How does this handle the suffix piece?

Re: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Grant Ingersoll <gs...@apache.org>.
On Dec 24, 2009, at 4:36 PM, Grant Ingersoll wrote:
> 
> 
>> What will the base class be for asking for a bounding box?
>> 
> 
> Actually, what I think I need is the subType/suffix handling separate from the dimension stuff.  I'll put up a patch in a few days.  Time to go eat some Christmas cookies.

See https://issues.apache.org/jira/browse/SOLR-1586 for my proposed refactoring.  Basically, I introduced a new base class for CoordinateFieldType that has the subtype/suffix handling, but not the dimension stuff, as the CartesianTierField only deals with lat/lon.

Re: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Grant Ingersoll <gs...@apache.org>.
On Dec 24, 2009, at 3:33 PM, Yonik Seeley wrote:

> On Thu, Dec 24, 2009 at 3:21 PM, Grant Ingersoll <gs...@apache.org> wrote:
>> Any objection to moving the suffix/subfield stuff up to CoordinateFieldType?  I'm working on the Cartesian Tier stuff and it has much the same pattern for this stuff.
> 
> I dunno... will it complicate things more?  What's the difference
> between CoordinateFieldType and PointFieldtype?

I envision you could have things like a ShapeFieldType that inherits from CoordinateFieldType (i.e. has a subtype and a dimension)


> What will the base class be for asking for a bounding box?
> 

Actually, what I think I need is the subType/suffix handling separate from the dimension stuff.  I'll put up a patch in a few days.  Time to go eat some Christmas cookies.

-Grant


Re: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Thu, Dec 24, 2009 at 3:21 PM, Grant Ingersoll <gs...@apache.org> wrote:
> Any objection to moving the suffix/subfield stuff up to CoordinateFieldType?  I'm working on the Cartesian Tier stuff and it has much the same pattern for this stuff.

I dunno... will it complicate things more?  What's the difference
between CoordinateFieldType and PointFieldtype?
What will the base class be for asking for a bounding box?

-Yonik
http://www.lucidimagination.com

Fwd: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java

Posted by Grant Ingersoll <gs...@apache.org>.
Any objection to moving the suffix/subfield stuff up to CoordinateFieldType?  I'm working on the Cartesian Tier stuff and it has much the same pattern for this stuff.

Begin forwarded message:

> From: yonik@apache.org
> Date: December 24, 2009 12:42:49 PM EST
> To: solr-commits@lucene.apache.org
> Subject: svn commit: r893792 - in /lucene/solr/trunk: example/solr/conf/schema.xml src/java/org/apache/solr/schema/CoordinateFieldType.java src/java/org/apache/solr/schema/FieldType.java src/java/org/apache/solr/schema/PointType.java
> Reply-To: solr-dev@lucene.apache.org
> 
> Author: yonik
> Date: Thu Dec 24 17:42:48 2009
> New Revision: 893792
> 
> 
> Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java
> URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java?rev=893792&r1=893791&r2=893792&view=diff
> ==============================================================================
> --- lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java (original)
> +++ lucene/solr/trunk/src/java/org/apache/solr/schema/CoordinateFieldType.java Thu Dec 24 17:42:48 2009
> @@ -55,7 +55,7 @@
>   protected FieldType subType;
>   public static final String SUB_FIELD_SUFFIX = "subFieldSuffix";
>   public static final String SUB_FIELD_TYPE = "subFieldType";
> -  private String suffix;//need to keep this around between init and inform, since dynamic fields aren't created until before inform
> +  protected String suffix;
>   protected int dynFieldProps;
> 
>   public int getDimension() {
> @@ -76,6 +76,7 @@
>     if (subFT != null) {
>       args.remove(SUB_FIELD_TYPE);
>       subType = schema.getFieldTypeByName(subFT.trim());
> +      suffix = POLY_FIELD_SEPARATOR + subType.typeName;      
>     } else if (subSuffix != null) {
>       args.remove(SUB_FIELD_SUFFIX);
>       suffix = subSuffix;
> @@ -90,18 +91,9 @@
> 
>   public void inform(IndexSchema schema) {
>     //Can't do this until here b/c the Dynamic Fields are not initialized until here.
> -    if (suffix != null){
> -      SchemaField sf = schema.getField(suffix);
> -      subType = sf.getType();//this means it is already registered
> -      dynFieldProps = sf.getProperties(); 
> -    }
> -    else if (subType != null) {
> +    if (subType != null) {
>       SchemaField proto = registerPolyFieldDynamicPrototype(schema, subType);
>       dynFieldProps = proto.getProperties();
> -    } else {
> -      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "The field type: " + typeName
> -              + " must specify the " +
> -      SUB_FIELD_TYPE + " attribute or the " + SUB_FIELD_SUFFIX + " attribute.");
>     }
>   }
> 
> 
>   /**
>    * Create the field from native Lucene parts.  Mostly intended for use by FieldTypes outputing multiple
>    * Fields per SchemaField
> 
> Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java
> URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java?rev=893792&r1=893791&r2=893792&view=diff
> ==============================================================================
> --- lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java (original)
> +++ lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java Thu Dec 24 17:42:48 2009
> @@ -54,7 +54,7 @@
>   public static final String DIMENSION = "dimension";
> 
>   protected IndexSchema schema;   // needed for retrieving SchemaFields
> -
> +  protected String[] suffixes;
> 
>   @Override
>   protected void init(IndexSchema schema, Map<String, String> args) {
> @@ -68,6 +68,15 @@
>     this.schema = schema;
>     super.init(schema, args);
> 
> +    // cache suffixes
> +    suffixes = new String[dimension];
> +    for (int i=0; i<dimension; i++) {
> +      suffixes[i] = "_" + i + suffix;
> +    }
> +  }
> +
> +  protected SchemaField subField(SchemaField base, int i) {
> +    return schema.getField(base.getName() + suffixes[i]);
>   }
> 
> 
> @@ -79,7 +88,24 @@
>   @Override
>   public Fieldable[] createFields(SchemaField field, String externalVal, float boost) {
>     String[] point = DistanceUtils.parsePoint(null, externalVal, dimension);
> -    return createFields(field, dynFieldProps, subType, externalVal, boost, point);
> +
> +    // TODO: this doesn't currently support polyFields as sub-field types
> +    Fieldable[] f = new Fieldable[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ];
> +
> +    if (field.indexed()) {
> +      for (int i=0; i<dimension; i++) {
> +        f[i] = subField(field, i).createField(point[i], boost);
> +      }
> +    }
> +
> +    if (field.stored()) {
> +      String storedVal = externalVal;  // normalize or not?
> +      f[f.length - 1] = createField(field.getName(), storedVal,
> +                getFieldStore(field, storedVal), Field.Index.NO, Field.TermVector.NO,
> +                false, false, boost);
> +    }
> +    
> +    return f;
>   }
> 
>   @Override
> @@ -119,50 +145,25 @@
>     String[] p1 = DistanceUtils.parsePoint(null, part1, dimension);
>     String[] p2 = DistanceUtils.parsePoint(null, part2, dimension);
>     BooleanQuery result = new BooleanQuery(true);
> -    String name = field.getName() + "_";
> -    String suffix = POLY_FIELD_SEPARATOR + subType.typeName;
> -    int len = name.length();
> -    StringBuilder bldr = new StringBuilder(len + 3 + suffix.length());//should be enough buffer to handle most values of j.
> -    bldr.append(name);
>     for (int i = 0; i < dimension; i++) {
> -      bldr.append(i).append(suffix);
> -      SchemaField subSF = schema.getField(bldr.toString());
> +      SchemaField subSF = subField(field, i);
>       // points must currently be ordered... should we support specifying any two opposite corner points?
> -
> -      /*new TermRangeQuery(
> -     field.getName() + i + POLY_FIELD_SEPARATOR + subType.typeName,
> -     subType.toInternal(p1[i]),
> -     subType.toInternal(p2[i]),
> -     minInclusive, maxInclusive);*/
> -      result.add(subType.getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
> -      bldr.setLength(len);
> +      result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
>     }
>     return result;
>   }
> 
>   @Override
>   public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
> -    Query result = null;
> -
>     String[] p1 = DistanceUtils.parsePoint(null, externalVal, dimension);
>     //TODO: should we assert that p1.length == dimension?
>     BooleanQuery bq = new BooleanQuery(true);
> -    String name = field.getName() + "_";
> -    String suffix = POLY_FIELD_SEPARATOR + subType.typeName;
> -    int len = name.length();
> -    StringBuilder bldr = new StringBuilder(len + 3 + suffix.length());//should be enough buffer to handle most values of j.
> -    bldr.append(name);
>     for (int i = 0; i < dimension; i++) {
> -      bldr.append(i).append(suffix);
> -      SchemaField sf1 = schema.getField(bldr.toString());
> -      Query tq = subType.getFieldQuery(parser, sf1, p1[i]);
> -      //new TermQuery(new Term(bldr.toString(), subType.toInternal(p1[i])));
> +      SchemaField sf = subField(field, i);
> +      Query tq = sf.getType().getFieldQuery(parser, sf, p1[i]);
>       bq.add(tq, BooleanClause.Occur.MUST);
> -      bldr.setLength(len);
>     }
> -    result = bq;
> -
> -    return result;
> +    return bq;
>   }
> 
>   class PointTypeValueSource extends MultiValueSource {
> @@ -272,5 +273,3 @@
>   }
> 
> }
> -
> -
> 
> 

--------------------------
Grant Ingersoll
http://www.lucidimagination.com/

Search the Lucene ecosystem using Solr/Lucene: http://www.lucidimagination.com/search