lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r893812 - in /lucene/solr/trunk/src/java/org/apache/solr: schema/PointType.java search/ToMultiValueSource.java
Date Thu, 24 Dec 2009 21:54:16 GMT
Author: yonik
Date: Thu Dec 24 21:54:12 2009
New Revision: 893812

URL: http://svn.apache.org/viewvc?rev=893812&view=rev
Log:
SOLR-1131: no need for point value source to recreate sub-value sources for each new reader.
 Make ToMultiValueSource slightly more generic, specialize for dimention=2, and make point
value source inherit from that

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/schema/PointType.java
    lucene/solr/trunk/src/java/org/apache/solr/search/ToMultiValueSource.java

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=893812&r1=893811&r2=893812&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 21:54:12 2009
@@ -32,12 +32,15 @@
 import org.apache.solr.request.XMLWriter;
 import org.apache.solr.search.MultiValueSource;
 import org.apache.solr.search.QParser;
+import org.apache.solr.search.ToMultiValueSource;
 import org.apache.solr.search.function.DocValues;
 import org.apache.solr.search.function.ValueSource;
 import org.apache.solr.search.function.distance.DistanceUtils;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * A point type that indexes a point in an n-dimensional space as separate fields and uses
@@ -110,7 +113,12 @@
 
   @Override
   public ValueSource getValueSource(SchemaField field, QParser parser) {
-    return new PointTypeValueSource(field, dimension, subType, parser);
+    ArrayList<ValueSource> vs = new ArrayList(dimension);
+    for (int i=0; i<dimension; i++) {
+      SchemaField sub = subField(field, i);
+      vs.add(sub.getType().getValueSource(sub, parser));
+    }
+    return new PointTypeValueSource(field, vs);
   }
 
 
@@ -165,108 +173,24 @@
     }
     return bq;
   }
+}
 
-  class PointTypeValueSource extends MultiValueSource {
-    protected SchemaField field;
-    protected FieldType subType;
-    protected int dimension;
-    private QParser parser;
-
-    public PointTypeValueSource(SchemaField field, int dimension, FieldType subType, QParser
parser) {
-      this.field = field;
-      this.dimension = dimension;
-      this.subType = subType;
-      this.parser = parser;
-    }
-
-    @Override
-    public void createWeight(Map context, Searcher searcher) throws IOException {
-      String name = field.getName();
-      String suffix = FieldType.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 sf = schema.getField(bldr.toString());
-        subType.getValueSource(sf, parser).createWeight(context, searcher);
-        bldr.setLength(len);
-      }
-    }
 
-    public int dimension() {
-      return dimension;
-    }
+class PointTypeValueSource extends ToMultiValueSource {
+  private final SchemaField sf;
+  
+  public PointTypeValueSource(SchemaField sf, List<ValueSource> sources) {
+    super(sources);
+    this.sf = sf;
+  }
 
-    @Override
-    public DocValues getValues(Map context, IndexReader reader) throws IOException {
-      final DocValues[] valsArr1 = new DocValues[dimension];
-      String name = field.getName();
-      String suffix = FieldType.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 sf = schema.getField(bldr.toString());
-        valsArr1[i] = subType.getValueSource(sf, parser).getValues(context, reader);
-        bldr.setLength(len);
-      }
-      return new DocValues() {
-        //TODO: not sure how to handle the other types at this moment
-        @Override
-        public void doubleVal(int doc, double[] vals) {
-          //TODO: check whether vals.length == dimension or assume its handled elsewhere?
-          for (int i = 0; i < dimension; i++) {
-            vals[i] = valsArr1[i].doubleVal(doc);
-          }
-        }
-
-
-        @Override
-        public String toString(int doc) {
-          StringBuilder sb = new StringBuilder("point(");
-          boolean firstTime = true;
-          for (DocValues docValues : valsArr1) {
-            if (firstTime == false) {
-              sb.append(",");
-            } else {
-              firstTime = true;
-            }
-            sb.append(docValues.toString(doc));
-          }
-          sb.append(")");
-          return sb.toString();
-        }
-      };
-    }
-
-    public String description() {
-      StringBuilder sb = new StringBuilder();
-      sb.append("point(");
-      sb.append("fld=").append(field.name).append(", subType=").append(subType.typeName)
-              .append(", dimension=").append(dimension).append(')');
-      return sb.toString();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (this == o) return true;
-      if (!(o instanceof PointTypeValueSource)) return false;
-
-      PointTypeValueSource that = (PointTypeValueSource) o;
-
-      if (dimension != that.dimension) return false;
-      if (!field.equals(that.field)) return false;
-      return true;
-    }
-
-    @Override
-    public int hashCode() {
-      int result = field.hashCode();
-      result = 31 * result + dimension;
-      return result;
-    }
+  @Override
+  public String name() {
+    return "point";
   }
 
-}
+  @Override
+  public String description() {
+    return name()+"("+sf.getName()+")";
+  }
+}
\ No newline at end of file

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/ToMultiValueSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/ToMultiValueSource.java?rev=893812&r1=893811&r2=893812&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/ToMultiValueSource.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/ToMultiValueSource.java Thu Dec 24 21:54:12
2009
@@ -47,13 +47,67 @@
     return sources.size();
   }
 
+  public String name() {
+    return "toMultiVS";
+  }
+
   @Override
   public DocValues getValues(Map context, IndexReader reader) throws IOException {
     int size = sources.size();
+
+    // special-case x,y and lat,lon since it's so common
+    if (size==2) {
+      final DocValues x = sources.get(0).getValues(context, reader);
+      final DocValues y = sources.get(1).getValues(context, reader);
+      return new DocValues() {
+        @Override
+        public void byteVal(int doc, byte[] vals) {
+          vals[0] = x.byteVal(doc);
+          vals[1] = y.byteVal(doc);
+        }
+
+        @Override
+        public void shortVal(int doc, short[] vals) {
+          vals[0] = x.shortVal(doc);
+          vals[1] = y.shortVal(doc);
+        }
+        @Override
+        public void intVal(int doc, int[] vals) {
+          vals[0] = x.intVal(doc);
+          vals[1] = y.intVal(doc);
+        }
+        @Override
+        public void longVal(int doc, long[] vals) {
+          vals[0] = x.longVal(doc);
+          vals[1] = y.longVal(doc);
+        }
+        @Override
+        public void floatVal(int doc, float[] vals) {
+          vals[0] = x.byteVal(doc);
+          vals[1] = y.byteVal(doc);
+        }
+        @Override
+        public void doubleVal(int doc, double[] vals) {
+          vals[0] = x.doubleVal(doc);
+          vals[1] = y.doubleVal(doc);
+        }
+        @Override
+        public void strVal(int doc, String[] vals) {
+          vals[0] = x.strVal(doc);
+          vals[1] = y.strVal(doc);
+        }
+        public String toString(int doc) {
+          return name() + "(" + x.toString(doc) + "," + y.toString(doc) + ")";
+        }
+      };
+    }
+
+
     final DocValues[] valsArr = new DocValues[size];
     for (int i = 0; i < size; i++) {
       valsArr[i] = sources.get(i).getValues(context, reader);
     }
+
     return new DocValues() {
       @Override
       public void byteVal(int doc, byte[] vals) {
@@ -107,7 +161,7 @@
       @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();
-        sb.append("toMultiVS(");
+        sb.append(name()).append('(');
         boolean firstTime = true;
         for (DocValues vals : valsArr) {
           if (firstTime) {
@@ -131,7 +185,7 @@
 
   public String description() {
     StringBuilder sb = new StringBuilder();
-    sb.append("toMultiVS(");
+    sb.append(name()).append('(');
     boolean firstTime = true;
     for (ValueSource source : sources) {
       if (firstTime) {



Mime
View raw message