SOLR-1131: change toMultiVS to vector

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@894183 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2009-12-28 14:41:18 +00:00
parent ef2a3e1a13
commit 2593733ce4
5 changed files with 19 additions and 23 deletions

View File

@ -19,21 +19,17 @@ package org.apache.solr.schema;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.SortField;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.TextResponseWriter;
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.VectorValueSource;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.distance.DistanceUtils;
@ -176,7 +172,7 @@ public class PointType extends CoordinateFieldType {
}
class PointTypeValueSource extends ToMultiValueSource {
class PointTypeValueSource extends VectorValueSource {
private final SchemaField sf;
public PointTypeValueSource(SchemaField sf, List<ValueSource> sources) {

View File

@ -203,9 +203,9 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
};
}
});
addParser("toMultiVS", new ValueSourceParser(){
addParser("vector", new ValueSourceParser(){
public ValueSource parse(FunctionQParser fp) throws ParseException{
return new ToMultiValueSource(fp.parseValueSourceList());
return new VectorValueSource(fp.parseValueSourceList());
}
});
addParser("query", new ValueSourceParser() {
@ -240,13 +240,13 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
List<ValueSource> s1 = new ArrayList<ValueSource>();
s1.add(one);
s1.add(two);
pv1 = new ToMultiValueSource(s1);
pv1 = new VectorValueSource(s1);
ValueSource x2 = fp.parseValueSource();
ValueSource y2 = fp.parseValueSource();
List<ValueSource> s2 = new ArrayList<ValueSource>();
s2.add(x2);
s2.add(y2);
pv2 = new ToMultiValueSource(s2);
pv2 = new VectorValueSource(s2);
} else {
//check to see if we have multiValue source
if (one instanceof MultiValueSource && two instanceof MultiValueSource){
@ -482,8 +482,8 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
//if one is a MultiValueSource, than the other one needs to be too.
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Illegal number of sources. There must be an even number of sources");
} else {
mvr.mv1 = new ToMultiValueSource(Collections.singletonList(sources.get(0)));
mvr.mv2 = new ToMultiValueSource(Collections.singletonList(sources.get(1)));
mvr.mv1 = new VectorValueSource(Collections.singletonList(sources.get(0)));
mvr.mv2 = new VectorValueSource(Collections.singletonList(sources.get(1)));
}
} else {
int dim = sources.size() / 2;
@ -491,8 +491,8 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
List<ValueSource> sources2 = new ArrayList<ValueSource>(dim);
//Get dim value sources for the first vector
splitSources(dim, sources, sources1, sources2);
mvr.mv1 = new ToMultiValueSource(sources1);
mvr.mv2 = new ToMultiValueSource(sources2);
mvr.mv1 = new VectorValueSource(sources1);
mvr.mv2 = new VectorValueSource(sources2);
}
return mvr;

View File

@ -31,11 +31,11 @@ import java.util.Map;
* i.e. {@link org.apache.solr.search.function.DocValues#doubleVal(int, double[])}
*/
//Not crazy about the name, but...
public class ToMultiValueSource extends MultiValueSource {
public class VectorValueSource extends MultiValueSource {
protected List<ValueSource> sources;
public ToMultiValueSource(List<ValueSource> sources) {
public VectorValueSource(List<ValueSource> sources) {
this.sources = sources;
}
@ -48,7 +48,7 @@ public class ToMultiValueSource extends MultiValueSource {
}
public String name() {
return "toMultiVS";
return "vector";
}
@Override
@ -202,9 +202,9 @@ public class ToMultiValueSource extends MultiValueSource {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ToMultiValueSource)) return false;
if (!(o instanceof VectorValueSource)) return false;
ToMultiValueSource that = (ToMultiValueSource) o;
VectorValueSource that = (VectorValueSource) o;
if (!sources.equals(that.sources)) return false;

View File

@ -143,10 +143,10 @@ public class PolyFieldTest extends AbstractSolrTestCase {
"//*[@numFound='1']",
"//str[@name='homed'][.='1000,10000']");
assertQ(req("fl", "*,score", "q",
"{!func}sqedist(home, toMultiVS(0, 0))"),
"{!func}sqedist(home, vector(0, 0))"),
"\"//*[@numFound='50']\"");
assertQ(req("fl", "*,score", "q",
"{!func}dist(2, home, toMultiVS(0, 0))"),
"{!func}dist(2, home, vector(0, 0))"),
"\"//*[@numFound='50']\"");
assertQ(req("fl", "*,score", "q",

View File

@ -117,10 +117,10 @@ public class DistanceFunctionTest extends AbstractSolrTestCase {
//Do point tests:
assertQ(req("fl", "*,score", "q", "{!func}dist(1, toMultiVS(x_td, y_td), toMultiVS(0, 0))", "fq", "id:5"),
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, toMultiVS(0, 0))", "fq", "id:6"),
assertQ(req("fl", "*,score", "q", "{!func}dist(1, point, vector(0, 0))", "fq", "id:6"),
"//float[@name='score']='" + 1.0f + "'");
}