Example usage for org.apache.lucene.queries.function.valuesource VectorValueSource VectorValueSource

List of usage examples for org.apache.lucene.queries.function.valuesource VectorValueSource VectorValueSource

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function.valuesource VectorValueSource VectorValueSource.

Prototype

public VectorValueSource(List<ValueSource> sources) 

Source Link

Usage

From source file:com.gogobot.DistanceParser.java

License:Apache License

/** make a MultiValueSource from two non MultiValueSources */
private VectorValueSource makeMV(List<ValueSource> sources, List<ValueSource> orig) throws SyntaxError {
    ValueSource vs1 = sources.get(0);//from ww w.  j a  v a 2s .c o m
    ValueSource vs2 = sources.get(1);

    if (vs1 instanceof MultiValueSource || vs2 instanceof MultiValueSource) {
        throw new SyntaxError("geodist - invalid parameters:" + orig);
    }
    return new VectorValueSource(sources);
}

From source file:com.gogobot.DistanceParser.java

License:Apache License

private MultiValueSource parsePoint(FunctionQParser fp) throws SyntaxError {
    String pt = fp.getParam(SpatialParams.POINT);
    if (pt == null)
        return null;
    double[] point = null;
    try {/*from  w  w w.  ja va  2  s.  c  om*/
        point = ParseUtils.parseLatitudeLongitude(pt);
    } catch (InvalidShapeException e) {
        throw new SyntaxError("Bad spatial pt:" + pt);
    }
    return new VectorValueSource(Arrays.<ValueSource>asList(new DoubleConstValueSource(point[0]),
            new DoubleConstValueSource(point[1])));
}

From source file:org.apache.solr.search.FunctionQParser.java

License:Apache License

@Override
public Query parse() throws SyntaxError {
    sp = new QueryParsing.StrParser(getString());

    ValueSource vs = null;//from   w  ww. ja  va 2s  .  co m
    List<ValueSource> lst = null;

    for (;;) {
        ValueSource valsource = parseValueSource(false);
        sp.eatws();
        if (!parseMultipleSources) {
            vs = valsource;
            break;
        } else {
            if (lst != null) {
                lst.add(valsource);
            } else {
                vs = valsource;
            }
        }

        // check if there is a "," separator
        if (sp.peek() != ',')
            break;

        consumeArgumentDelimiter();

        if (lst == null) {
            lst = new ArrayList<ValueSource>(2);
            lst.add(valsource);
        }
    }

    if (parseToEnd && sp.pos < sp.end) {
        throw new SyntaxError("Unexpected text after function: " + sp.val.substring(sp.pos, sp.end));
    }

    if (lst != null) {
        vs = new VectorValueSource(lst);
    }

    return new FunctionQuery(vs);
}

From source file:org.apache.solr.search.ValueSourceParser.java

License:Apache License

private static MVResult getMultiValueSources(List<ValueSource> sources) {
    MVResult mvr = new MVResult();
    if (sources.size() % 2 != 0) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "Illegal number of sources.  There must be an even number of sources");
    }/*www.  java  2 s.c o  m*/
    if (sources.size() == 2) {

        //check to see if these are MultiValueSource
        boolean s1MV = sources.get(0) instanceof MultiValueSource;
        boolean s2MV = sources.get(1) instanceof MultiValueSource;
        if (s1MV && s2MV) {
            mvr.mv1 = (MultiValueSource) sources.get(0);
            mvr.mv2 = (MultiValueSource) sources.get(1);
        } else if (s1MV || s2MV) {
            //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 VectorValueSource(Collections.singletonList(sources.get(0)));
            mvr.mv2 = new VectorValueSource(Collections.singletonList(sources.get(1)));
        }
    } else {
        int dim = sources.size() / 2;
        List<ValueSource> sources1 = new ArrayList<ValueSource>(dim);
        List<ValueSource> sources2 = new ArrayList<ValueSource>(dim);
        //Get dim value sources for the first vector
        splitSources(dim, sources, sources1, sources2);
        mvr.mv1 = new VectorValueSource(sources1);
        mvr.mv2 = new VectorValueSource(sources2);
    }

    return mvr;
}