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: yo...@apache.org
> Date: December 24, 2009 12:42:49 PM EST
> To: solr-comm...@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

Reply via email to