lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r895455 [2/2] - in /lucene/solr/branches/cloud: ./ contrib/clustering/ contrib/clustering/src/main/java/org/apache/solr/handler/clustering/carrot2/ example/exampledocs/ example/solr/conf/ src/common/org/apache/solr/common/ src/java/org/apac...
Date Sun, 03 Jan 2010 18:06:49 GMT
Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
(original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
Sun Jan  3 18:06:36 2010
@@ -21,9 +21,9 @@
 import org.apache.solr.common.SolrException;
 import org.apache.solr.search.function.DocValues;
 import org.apache.solr.search.function.ValueSource;
+import org.apache.solr.search.function.MultiValueSource;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.Map;
 
 
@@ -41,18 +41,18 @@
  * @see SquaredEuclideanFunction for the special case
  */
 public class VectorDistanceFunction extends ValueSource {
-  protected List<ValueSource> sources1, sources2;
+  protected MultiValueSource source1, source2;
   protected float power;
   protected float oneOverPower;
 
-  public VectorDistanceFunction(float power, List<ValueSource> sources1, List<ValueSource>
sources2) {
-    this.power = power;
-    this.oneOverPower = 1 / power;
-    this.sources1 = sources1;
-    this.sources2 = sources2;
-    if ((sources1.size() != sources2.size())) {
+  public VectorDistanceFunction(float power, MultiValueSource source1, MultiValueSource source2)
{
+    if ((source1.dimension() != source2.dimension())) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Illegal number of sources");
     }
+    this.power = power;
+    this.oneOverPower = 1 / power;
+    this.source1 = source1;
+    this.source2 = source2;
   }
 
   protected String name() {
@@ -63,37 +63,39 @@
    * Calculate the distance
    *
    * @param doc        The current doc
-   * @param docValues1 The values from the first set of value sources
-   * @param docValues2 The values from the second set of value sources
+   * @param dv1 The values from the first MultiValueSource
+   * @param dv2 The values from the second MultiValueSource
    * @return The distance
    */
-  protected double distance(int doc, DocValues[] docValues1, DocValues[] docValues2) {
+  protected double distance(int doc, DocValues dv1, DocValues dv2) {
     double result = 0;
     //Handle some special cases:
+    double [] vals1 = new double[source1.dimension()];
+    double [] vals2 = new double[source1.dimension()];
+    dv1.doubleVal(doc, vals1);
+    dv2.doubleVal(doc, vals2);
     if (power == 0) {
-      for (int i = 0; i < docValues1.length; i++) {
-        //sparseness measure
-        result += docValues1[i].doubleVal(doc) - docValues2[i].doubleVal(doc) == 0 ? 0 :
1;
+      for (int i = 0; i < vals1.length; i++) {
+        result += vals1[i] - vals2[i] == 0 ? 0 :1;
       }
+
     } else if (power == 1.0) {
-      for (int i = 0; i < docValues1.length; i++) {
-        result += docValues1[i].doubleVal(doc) - docValues2[i].doubleVal(doc);
+      for (int i = 0; i < vals1.length; i++) {
+        result += vals1[i] - vals2[i];
       }
     } else if (power == 2.0) {
-      for (int i = 0; i < docValues1.length; i++) {
-        double v = docValues1[i].doubleVal(doc) - docValues2[i].doubleVal(doc);
+      for (int i = 0; i < vals1.length; i++) {
+        double v = vals1[i] - vals2[i];
         result += v * v;
       }
       result = Math.sqrt(result);
     } else if (power == Integer.MAX_VALUE || Double.isInfinite(power)) {//infininte norm?
-      for (int i = 0; i < docValues1.length; i++) {
-        //TODO: is this the correct infinite norm?
-        result = Math.max(docValues1[i].doubleVal(doc) - docValues2[i].doubleVal(doc), result);
+      for (int i = 0; i < vals1.length; i++) {
+        result = Math.max(vals1[i], vals2[i]);
       }
-
     } else {
-      for (int i = 0; i < docValues1.length; i++) {
-        result += Math.pow(docValues1[i].doubleVal(doc) - docValues2[i].doubleVal(doc), power);
+      for (int i = 0; i < vals1.length; i++) {
+        result += Math.pow(vals1[i] - vals2[i], power);
       }
       result = Math.pow(result, oneOverPower);
     }
@@ -103,19 +105,24 @@
 
   @Override
   public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues[] valsArr1 = new DocValues[sources1.size()];
-    int i = 0;
-    for (ValueSource source : sources1) {
-      valsArr1[i++] = source.getValues(context, reader);
-    }
-    final DocValues[] valsArr2 = new DocValues[sources2.size()];
-    i = 0;
-    for (ValueSource source : sources2) {
-      valsArr2[i++] = source.getValues(context, reader);
-    }
+
+    final DocValues vals1 = source1.getValues(context, reader);
+
+    final DocValues vals2 = source2.getValues(context, reader);
+
 
 
     return new DocValues() {
+      @Override
+      public byte byteVal(int doc) {
+        return (byte) doubleVal(doc);
+      }
+
+      @Override
+      public short shortVal(int doc) {
+        return (short)doubleVal(doc);
+      }
+
       public float floatVal(int doc) {
         return (float) doubleVal(doc);
       }
@@ -129,7 +136,7 @@
       }
 
       public double doubleVal(int doc) {
-        return distance(doc, valsArr1, valsArr2);
+        return distance(doc, vals1, vals2);
       }
 
       public String strVal(int doc) {
@@ -141,18 +148,8 @@
         StringBuilder sb = new StringBuilder();
         sb.append(name()).append('(').append(power).append(',');
         boolean firstTime = true;
-        for (DocValues vals : valsArr1) {
-          if (firstTime) {
-            firstTime = false;
-          } else {
-            sb.append(',');
-          }
-          sb.append(vals.toString(doc));
-        }
-        for (DocValues vals : valsArr2) {
-          sb.append(',');//we will always have valsArr1, else there is an error
-          sb.append(vals.toString(doc));
-        }
+        sb.append(vals1.toString(doc)).append(',');
+        sb.append(vals2.toString(doc));
         sb.append(')');
         return sb.toString();
       }
@@ -161,12 +158,8 @@
 
   @Override
   public void createWeight(Map context, Searcher searcher) throws IOException {
-    for (ValueSource source : sources1) {
-      source.createWeight(context, searcher);
-    }
-    for (ValueSource source : sources2) {
-      source.createWeight(context, searcher);
-    }
+    source1.createWeight(context, searcher);
+    source2.createWeight(context, searcher);
   }
 
   @Override
@@ -177,16 +170,16 @@
     VectorDistanceFunction that = (VectorDistanceFunction) o;
 
     if (Float.compare(that.power, power) != 0) return false;
-    if (!sources1.equals(that.sources1)) return false;
-    if (!sources2.equals(that.sources2)) return false;
+    if (!source1.equals(that.source1)) return false;
+    if (!source2.equals(that.source2)) return false;
 
     return true;
   }
 
   @Override
   public int hashCode() {
-    int result = sources1.hashCode();
-    result = 31 * result + sources2.hashCode();
+    int result = source1.hashCode();
+    result = 31 * result + source2.hashCode();
     result = 31 * result + Float.floatToRawIntBits(power);
     return result;
   }
@@ -195,19 +188,8 @@
   public String description() {
     StringBuilder sb = new StringBuilder();
     sb.append(name()).append('(').append(power).append(',');
-    boolean firstTime = true;
-    for (ValueSource source : sources1) {
-      if (firstTime) {
-        firstTime = false;
-      } else {
-        sb.append(',');
-      }
-      sb.append(source);
-    }
-    for (ValueSource source : sources2) {
-      sb.append(',');//we will always have sources1, else there is an error
-      sb.append(source);
-    }
+    sb.append(source1).append(',');
+    sb.append(source2);
     sb.append(')');
     return sb.toString();
   }

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/update/DocumentBuilder.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/update/DocumentBuilder.java Sun Jan
 3 18:06:36 2010
@@ -57,19 +57,35 @@
     // we don't check for a null val ourselves because a solr.FieldType
     // might actually want to map it to something.  If createField()
     // returns null, then we don't store the field.
-    Field field = sfield.createField(val, boost);
-    if (field != null) {
-      if (!sfield.multiValued()) {
-        String oldValue = map.put(sfield.getName(), val);
-        if (oldValue != null) {
-          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple values
encountered for non multiValued field " + sfield.getName()
-                  + ": first='" + oldValue + "' second='" + val + "'");
+    if (sfield.isPolyField()) {
+      Fieldable[] fields = sfield.createFields(val, boost);
+      if (fields.length > 0) {
+        if (!sfield.multiValued()) {
+          String oldValue = map.put(sfield.getName(), val);
+          if (oldValue != null) {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "ERROR: multiple
values encountered for non multiValued field " + sfield.getName()
+                    + ": first='" + oldValue + "' second='" + val + "'");
+          }
+        }
+        // Add each field
+        for (Fieldable field : fields) {
+          doc.add(field);
+        }
+      }
+    } else {
+      Field field = sfield.createField(val, boost);
+      if (field != null) {
+        if (!sfield.multiValued()) {
+          String oldValue = map.put(sfield.getName(), val);
+          if (oldValue != null) {
+            throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple
values encountered for non multiValued field " + sfield.getName()
+                    + ": first='" + oldValue + "' second='" + val + "'");
+          }
         }
       }
-       
-      // field.setBoost(boost);
       doc.add(field);
     }
+
   }
 
   /**
@@ -147,7 +163,7 @@
     for (SchemaField field : schema.getRequiredFields()) {
       if (doc.getField(field.getName() ) == null) {
         if (field.getDefaultValue() != null) {
-          doc.add( field.createField( field.getDefaultValue(), 1.0f ) );
+          addField(doc, field, field.getDefaultValue(), 1.0f);
         } else {
           if (missingFields==null) {
             missingFields = new ArrayList<String>(1);
@@ -176,6 +192,19 @@
     Document ret = doc; doc=null;
     return ret;
   }
+
+
+  private static void addField(Document doc, SchemaField field, String val, float boost)
{
+    if (field.isPolyField()) {
+      Fieldable[] farr = field.getType().createFields(field, val, boost);
+      for (Fieldable f : farr) {
+        if (f != null) doc.add(f); // null fields are not added
+      }
+    } else {
+      Field f = field.createField(val, boost);
+      if (f != null) doc.add(f);  // null fields are not added
+    }
+  }
   
 
   /**
@@ -230,7 +259,9 @@
           isBinaryField = true;
           BinaryField binaryField = (BinaryField) sfield.getType();
           Field f = binaryField.createField(sfield,v,boost);
-          if(f != null) out.add(f);
+          if(f != null){
+            out.add(f);
+          }
           used = true;
         } else {
           // TODO!!! HACK -- date conversion
@@ -243,10 +274,7 @@
 
           if (sfield != null) {
             used = true;
-            Field f = sfield.createField(val, boost);
-            if (f != null) { // null fields are not added
-              out.add(f);
-            }
+            addField(out, sfield, val, boost);
           }
         }
 
@@ -263,17 +291,21 @@
           }
 
           used = true;
-          Field f = null;
+          //Don't worry about poly fields here
+          Fieldable [] fields = null;
           if (isBinaryField) {
             if (destinationField.getType() instanceof BinaryField) {
               BinaryField binaryField = (BinaryField) destinationField.getType();
-              f = binaryField.createField(destinationField, v, boost);
+              //TODO: safe to assume that binary fields only create one?
+              fields = new Field[]{binaryField.createField(destinationField, v, boost)};
             }
           } else {
-            f = destinationField.createField(cf.getLimitedValue(val), boost);
+            fields = destinationField.createFields(cf.getLimitedValue(val), boost);
           }
-          if (f != null) { // null fields are not added
-            out.add(f);
+          if (fields != null) { // null fields are not added
+            for (Fieldable f : fields) {
+              out.add(f);
+            }
           }
         }
         
@@ -297,7 +329,7 @@
     for (SchemaField field : schema.getRequiredFields()) {
       if (out.getField(field.getName() ) == null) {
         if (field.getDefaultValue() != null) {
-          out.add( field.createField( field.getDefaultValue(), 1.0f ) );
+          addField(out, field, field.getDefaultValue(), 1.0f);
         } 
         else {
           String id = schema.printableUniqueKey( out );

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/util/AbstractSolrTestCase.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/util/AbstractSolrTestCase.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/util/AbstractSolrTestCase.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/util/AbstractSolrTestCase.java Sun
Jan  3 18:06:36 2010
@@ -231,6 +231,17 @@
     }
   }
 
+  public void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code
) {
+    try {
+      h.query(req);
+      fail( message );
+    } catch (SolrException e) {
+      assertEquals( code.code, e.code() );
+    } catch (Exception e2) {
+      throw new RuntimeException("Exception during query", e2);
+    }
+  }
+
   
   /**
    * @see TestHarness#optimize

Modified: lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
(original)
+++ lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
Sun Jan  3 18:06:36 2010
@@ -43,7 +43,7 @@
 
 /**
  * StreamingHttpSolrServer buffers all added documents and writes them
- * into open http connections. This class is thread safe.
+ * into open HTTP connections. This class is thread safe.
  * 
  * Although any SolrServer request can be made with this implementation, 
  * it is only recommended to use the {@link StreamingUpdateSolrServer} with
@@ -66,9 +66,9 @@
   /**
    * Uses an internal MultiThreadedHttpConnectionManager to manage http connections
    *
-   * @param solrServerUrl The solr server url
-   * @param queueSize     The buffer size before the documents are sent o the server
-   * @param threadCount   The number of backgtound threads used to empty the queue
+   * @param solrServerUrl The Solr server URL
+   * @param queueSize     The buffer size before the documents are sent to the server
+   * @param threadCount   The number of background threads used to empty the queue
    * @throws MalformedURLException
    */
   public StreamingUpdateSolrServer(String solrServerUrl, int queueSize, int threadCount)
throws MalformedURLException {
@@ -76,7 +76,7 @@
   }
 
   /**
-   * Uses the supplied HttpClient to send documents to the solr server, the HttpClient should
be instantiated using a
+   * Uses the supplied HttpClient to send documents to the Solr server, the HttpClient should
be instantiated using a
    * MultiThreadedHttpConnectionManager.
    */
   public StreamingUpdateSolrServer(String solrServerUrl, HttpClient client, int queueSize,
int threadCount) throws MalformedURLException {
@@ -224,7 +224,7 @@
       }
     } 
     catch (InterruptedException e) {
-      log.error( "interuped", e );
+      log.error( "interrupted", e );
       throw new IOException( e.getLocalizedMessage() );
     }
     

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/BaseDistributedSearchTestCase.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/BaseDistributedSearchTestCase.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/BaseDistributedSearchTestCase.java
(original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/BaseDistributedSearchTestCase.java
Sun Jan  3 18:06:36 2010
@@ -35,6 +35,16 @@
 public abstract class BaseDistributedSearchTestCase extends AbstractSolrTestCase {
   public static Random r = new Random(0);
 
+  protected int shardCount = 4;
+  /**
+   * Sub classes can set this flag in their constructor to true if they
+   * want to fix the number of shards to 'shardCount'
+   *
+   * The default is false which means that test will be executed with
+   * 1, 2, 3, ....shardCount number of shards repeatedly
+   */
+  protected boolean fixShardCount = false;
+
   protected JettySolrRunner controlJetty;
   protected List<SolrServer> clients = new ArrayList<SolrServer>();
   protected List<JettySolrRunner> jettys = new ArrayList<JettySolrRunner>();
@@ -522,11 +532,18 @@
   }
 
   public void testDistribSearch() throws Exception {
-    for (int nServers = 1; nServers < 2; nServers++) {
-      createServers(nServers);
+    if (fixShardCount) {
+      createServers(shardCount);
       RandVal.uniqueValues = new HashSet(); //reset random values
       doTest();
       destroyServers();
+    } else {
+      for (int nServers = 1; nServers < shardCount; nServers++) {
+        createServers(nServers);
+        RandVal.uniqueValues = new HashSet(); //reset random values
+        doTest();
+        destroyServers();
+      }
     }
   }
 

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
(original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
Sun Jan  3 18:06:36 2010
@@ -30,6 +30,8 @@
     handle.put("QTime", SKIPVAL);
     handle.put("timestamp", SKIPVAL);
     handle.put("maxScore", SKIPVAL);
+    // we care only about the spellcheck results
+    handle.put("response", SKIP);
 
     query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","toyata", "spellcheck", "true",
SpellCheckComponent.SPELLCHECK_BUILD, "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH");
     query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","toyata", "spellcheck", "true",
SpellCheckComponent.SPELLCHECK_BUILD, "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH",
SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
(original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
Sun Jan  3 18:06:36 2010
@@ -16,9 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.lucene.spatial.geohash.GeoHashUtils;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.util.AbstractSolrTestCase;
-import org.apache.lucene.spatial.geohash.GeoHashUtils;
 
 
 /**
@@ -44,20 +44,31 @@
     assertU(adoc("id", "2", "x_td", "0", "y_td", String.valueOf(Math.PI / 2), "gh_s", GeoHashUtils.encode(32.7693246,
-78.9289094)));
     assertU(adoc("id", "3", "x_td", String.valueOf(Math.PI / 2), "y_td", String.valueOf(Math.PI
/ 2), "gh_s", GeoHashUtils.encode(32.7693246, -80.9289094)));
     assertU(adoc("id", "4", "x_td", String.valueOf(Math.PI / 4), "y_td", String.valueOf(Math.PI
/ 4), "gh_s", GeoHashUtils.encode(32.7693246, -81.9289094)));
+    assertU(adoc("id", "5", "x_td", "45.0", "y_td", "45.0",
+            "gh_s", GeoHashUtils.encode(32.7693246, -81.9289094)));
+    assertU(adoc("id", "6", "point_hash", "32.5, -79.0"));
+    assertU(adoc("id", "7", "point_hash", "32.6, -78.0"));
     assertU(commit());
     //Get the haversine distance between the point 0,0 and the docs above assuming a radius
of 1
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(x_td, y_td, 0, 0, 1)", "fq", "id:1"),
"//float[@name='score']='0.0'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(x_td, y_td, 0, 0, 1)", "fq", "id:2"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(x_td, y_td, 0, 0, 1)", "fq", "id:3"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(x_td, y_td, 0, 0, 1)", "fq", "id:4"),
"//float[@name='score']='1.0471976'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:1"),
"//float[@name='score']='0.0'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:2"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:3"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:4"),
"//float[@name='score']='1.0471976'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0, true)", "fq", "id:5"),
"//float[@name='score']='1.0471976'");
 
     //Geo Hash Haversine
     //Can verify here: http://www.movable-type.co.uk/scripts/latlong.html, but they use a
slightly different radius for the earth, so just be close
-    assertQ(req("fl", "*,score", "q", "{!func}ghhsin(gh_s, \"" + GeoHashUtils.encode(32,
-79) +
-            "\"," + Constants.EARTH_RADIUS_KM +
-            ")", "fq", "id:1"), "//float[@name='score']='122.30894'");
-    assertQ(req("fl", "*,score", "q", "{!func}ghhsin(gh_s, geohash(32, -79)," + Constants.EARTH_RADIUS_KM
+
-            ")", "fq", "id:1"), "//float[@name='score']='122.30894'");
+    assertQ(req("fl", "*,score", "q", "{!func}ghhsin(" + Constants.EARTH_RADIUS_KM + ", gh_s,
\"" + GeoHashUtils.encode(32, -79) +
+            "\",)", "fq", "id:1"), "//float[@name='score']='122.30894'");
+
+    assertQ(req("fl", "id,point_hash,score", "q", "{!func}recip(ghhsin(" + Constants.EARTH_RADIUS_KM
+ ", point_hash, \"" + GeoHashUtils.encode(32, -79) + "\"), 1, 1, 0)"),
+            "//*[@numFound='7']", 
+            "//result/doc[1]/float[@name='id'][.='6.0']",
+            "//result/doc[2]/float[@name='id'][.='7.0']"//all the rest don't matter
+            );
+
+
+    assertQ(req("fl", "*,score", "q", "{!func}ghhsin(" + Constants.EARTH_RADIUS_KM + ", gh_s,
geohash(32, -79))", "fq", "id:1"), "//float[@name='score']='122.30894'");
   }
 
   public void testVector() throws Exception {
@@ -66,6 +77,8 @@
     assertU(adoc("id", "3", "x_td", "1", "y_td", "1", "z_td", "1", "w_td", "1"));
     assertU(adoc("id", "4", "x_td", "1", "y_td", "0", "z_td", "0", "w_td", "0"));
     assertU(adoc("id", "5", "x_td", "2.3", "y_td", "5.5", "z_td", "7.9", "w_td", "-2.4"));
+    assertU(adoc("id", "6", "point", "1.0,0.0"));
+    assertU(adoc("id", "7", "point", "5.5,10.9"));
     assertU(commit());
     //two dimensions, notice how we only pass in 4 value sources
     assertQ(req("fl", "*,score", "q", "{!func}sqedist(x_td, y_td, 0, 0)", "fq", "id:1"),
"//float[@name='score']='0.0'");
@@ -111,6 +124,15 @@
     assertQ(req("fl", "*,score", "q", "{!func}dist(1, x_td, y_td, 0, 0)", "fq", "id:3"),
"//float[@name='score']='" + (float) 2.0 + "'");
     assertQ(req("fl", "*,score", "q", "{!func}dist(1, x_td, y_td, 0, 0)", "fq", "id:4"),
"//float[@name='score']='1.0'");
     assertQ(req("fl", "*,score", "q", "{!func}dist(1, x_td, y_td, 0, 0)", "fq", "id:5"),
"//float[@name='score']='" + (float) (2.3 + 5.5) + "'");
+
+
+    //Do point tests:
+    assertQ(req("fl", "*,score", "q", "{!func}dist(1, vector(x_td, y_td), vector(0, 0))",
"fq", "id:5"),
+            "//float[@name='score']='" + (float) (2.3 + 5.5) + "'");
+
+    assertQ(req("fl", "*,score", "q", "{!func}dist(1, point, vector(0, 0))", "fq", "id:6"),
+            "//float[@name='score']='" + 1.0f + "'");
+
   }
 
 }

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/update/DocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/update/DocumentBuilderTest.java?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/update/DocumentBuilderTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/update/DocumentBuilderTest.java Sun
Jan  3 18:06:36 2010
@@ -22,6 +22,7 @@
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.util.AbstractSolrTestCase;
+import org.apache.solr.schema.FieldType;
 
 /**
  * 
@@ -59,4 +60,17 @@
     Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
     assertNull( out.get( "name" ) );
   }
+
+  public void testMultiField() throws Exception {
+    SolrCore core = h.getCore();
+
+    // make sure a null value is not indexed
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField( "home", "2.2,3.3", 1.0f );
+    Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
+    assertNotNull( out.get( "home" ) );//contains the stored value and term vector, if there
is one
+    assertNotNull( out.getField( "home_0" + FieldType.POLY_FIELD_SEPARATOR + "double" ) );
+    assertNotNull( out.getField( "home_1" + FieldType.POLY_FIELD_SEPARATOR + "double" ) );
+  }
+
 }

Modified: lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema.xml?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema.xml (original)
+++ lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema.xml Sun Jan  3 18:06:36
2010
@@ -367,7 +367,15 @@
   </fieldtype>
 
   <fieldType name="uuid" class="solr.UUIDField" />
-  
+    
+    <!-- Try out some point types -->
+  <fieldType name="xy" class="solr.PointType" dimension="2" subFieldType="double"/>
+  <fieldType name="tenD" class="solr.PointType" dimension="10" subFieldType="double"/>
+    <!-- Use the sub field suffix -->
+  <fieldType name="xyd" class="solr.PointType" dimension="2" subFieldSuffix="*_d"/>
+
+  <fieldType name="tier" class="solr.SpatialTileField" start="4" end="15" subFieldType="double"/>
+
  </types>
 
 
@@ -392,6 +400,17 @@
    <field name="shouldbestored" type="unstored" stored="true"/>
    <field name="shouldbeunindexed" type="unstored" indexed="false" stored="true"/>
 
+   <!-- Test points -->
+      <!-- Test points -->
+   <field name="home" type="xy" indexed="true" stored="true" multiValued="false"/>
+   <field name="homed" type="xyd" indexed="true" stored="true" multiValued="false"/>
+   <field name="home_ns" type="xy" indexed="true" stored="false" multiValued="false"/>
+   <field name="work" type="xy" indexed="true" stored="true" multiValued="false"/>
+
+   <field name="home_tier" type="tier" indexed="true" stored="true" multiValued="false"/>
+
+   <field name="point10" type="tenD" indexed="true" stored="true" multiValued="false"/>
+
 
    <!-- test different combinations of indexed and stored -->
    <field name="bind" type="boolean" indexed="true" stored="false"/>
@@ -505,6 +524,8 @@
    <dynamicField name="tv_mv_*"  type="text" indexed="true"  stored="true" multiValued="true"
       termVectors="true" termPositions="true" termOffsets="true"/>
 
+   <dynamicField name="*_p"  type="xyd" indexed="true"  stored="true" multiValued="false"/>

+
    <!-- special fields for dynamic copyField test -->
    <dynamicField name="dynamic_*" type="string" indexed="true" stored="true"/>
    <dynamicField name="*_dynamic" type="string" indexed="true" stored="true"/>

Modified: lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema11.xml
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema11.xml?rev=895455&r1=895454&r2=895455&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema11.xml (original)
+++ lucene/solr/branches/cloud/src/test/test-files/solr/conf/schema11.xml Sun Jan  3 18:06:36
2010
@@ -251,6 +251,12 @@
     <fieldType name="tdoubles" class="solr.TrieDoubleField" omitNorms="true" positionIncrementGap="0"
precisionStep="0" multiValued="true" />
     <fieldType name="tdates" class="solr.TrieDateField" omitNorms="true" positionIncrementGap="0"
precisionStep="0" multiValued="true" />
 
+    <!-- Poly field -->
+    <fieldType name="xy" class="solr.PointType" dimension="2" subFieldType="double"/>
+    <fieldType name="xyd" class="solr.PointType" dimension="2" subFieldSuffix="*_d"/>
+
+    <fieldtype name="geohash" class="solr.GeoHashField"/>
+
  </types>
 
 
@@ -275,7 +281,13 @@
 
    <!-- for testing, a type that does a transform to see if it's correctly done everywhere
-->
    <field name="id" type="sfloat" indexed="true" stored="true" required="true" /> 
-   <field name="text" type="text" indexed="true" stored="false" /> 
+   <field name="text" type="text" indexed="true" stored="false" />
+
+   <!-- Test a point field for distances -->
+   <field name="point" type="xy" indexed="true" stored="true" multiValued="false"/>
+   <field name="pointD" type="xyd" indexed="true" stored="true" multiValued="false"/>
+
+   <field name="point_hash" type="geohash" indexed="true" stored="true" multiValued="false"/>
 
    <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
         will be used if the name matches any of the patterns.



Mime
View raw message