Example usage for org.apache.solr.search FunctionQParser hasMoreArguments

List of usage examples for org.apache.solr.search FunctionQParser hasMoreArguments

Introduction

In this page you can find the example usage for org.apache.solr.search FunctionQParser hasMoreArguments.

Prototype

public boolean hasMoreArguments() throws SyntaxError 

Source Link

Document

Are there more arguments in the argument list being parsed?

Usage

From source file:alba.solr.core.DynamicValueSourceParser.java

License:Apache License

@SuppressWarnings("unchecked")
public ValueSource parse(FunctionQParser fp) throws SyntaxError {

    String functionName;/*w  ww.  ja v  a2s .  c o m*/

    List<ValueSource> valueSourceList = new ArrayList<ValueSource>();

    functions = (Map<String, CallableFunction>) fp.getReq().getContext().get(Loader.FUNCTIONS);

    Map<String, ValueSource> values = new HashMap<String, ValueSource>();

    int i = 0;
    while (fp.hasMoreArguments()) {
        rawargs[i++] = fp.parseArg();
    }

    functionName = rawargs[0];

    CallableFunction function = functions.get(functionName);

    //still need this?

    // FunctionExecutionContext cachedEC = (FunctionExecutionContext)fp.getReq().getContext().get(fp.getString() );
    /* if (cachedEC != null) {
       logger.error("reusing executor from cache!");
       return cachedEC.getFunctionExecutor();
    } */

    for (int k = 1; k < i; k++) {
        String parts[] = rawargs[k].split("=");
        String name = parts[0];
        String value = parts[1];

        args.put(parts[0], parts[1]);

        if (value.startsWith("\"") && value.endsWith("\"")) {
            //probably quite ineffcient..
            String v = value.replaceAll("^\"", "").replaceAll("\"$", "");
            LiteralValueSource l = new LiteralValueSource(v);
            values.put(name, l);
            valueSourceList.add(l);
        } else if (NumberUtils.isNumber(value)) {
            ConstValueSource cvs = new ConstValueSource(Float.parseFloat(value));
            values.put(name, cvs);
            valueSourceList.add(cvs);
        } else {
            SchemaField f = fp.getReq().getSchema().getField(value);
            ValueSource vs = f.getType().getValueSource(f, fp);
            values.put(name, vs);
            valueSourceList.add(vs);
        }

    }

    FunctionExecutor executor = new FunctionExecutor(values, valueSourceList, fp, this);

    executor.setFunction(functions.get(functionName));

    // still need this????
    FunctionExecutionContext ec = new FunctionExecutionContext(fp.getString(), values, function, executor);
    fp.getReq().getContext().put(fp.getString(), ec);

    return executor;

}

From source file:com.ifactory.press.db.solr.HitCount.java

License:Apache License

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    // hitcount() takes no arguments.  If we wanted to pass a query
    // we could call fp.parseNestedQuery()
    HashSet<String> fields = new HashSet<String>();
    while (fp.hasMoreArguments()) {
        fields.add(fp.parseArg());/*  ww w. ja  v  a 2s .  c  o m*/
    }
    Query q = fp.subQuery(fp.getParams().get("q"), "lucene").getQuery();
    HashSet<Term> terms = new HashSet<Term>();
    try {
        q.extractTerms(terms);
    } catch (UnsupportedOperationException e) {
        return new DoubleConstValueSource(1);
    }
    ArrayList<ValueSource> termcounts = new ArrayList<ValueSource>();
    for (Term t : terms) {
        if (fields.isEmpty() || fields.contains(t.field())) {
            termcounts.add(new TermFreqValueSource(t.field(), t.text(), t.field(), t.bytes()));
        }
    }
    return new SumFloatFunction(termcounts.toArray(new ValueSource[termcounts.size()]));
}

From source file:net.semanticmetadata.lire.solr.LireValueSourceParser.java

License:Open Source License

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    String field = fp.parseArg(); // eg. cl_hi
    String featureString = fp.parseArg();
    // System.out.println(featureString);
    byte[] hist = Base64.decodeBase64(featureString); // eg. FQY5DhMYDg0ODg0PEBEPDg4ODg8QEgsgEBAQEBAgEBAQEBA=
    double maxDistance = Double.MAX_VALUE;
    if (fp.hasMoreArguments()) { // if there is a third argument, it's the max value to return if there is none. Note the query cache is not updated upon parameter change.
        maxDistance = Double.parseDouble(fp.parseArg());
    }/*w w  w .  jav  a2s  .  co m*/
    return new LireValueSource(field, hist, maxDistance);
}

From source file:org.opencommercesearch.lucene.queries.function.valuesource.FixedBoostValueSourceParser.java

License:Apache License

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    String field = fp.parseArg();

    SchemaField f = fp.getReq().getSchema().getField(field);
    ValueSource fieldValueSource = f.getType().getValueSource(f, fp);
    Map<String, Integer> positions = new HashMap<String, Integer>(DEFAULT_BOOST_COUNT);
    int position = 0;

    while (fp.hasMoreArguments()) {
        positions.put(fp.parseArg(), position++);
    }/*from www.  j a  va 2 s  .  c  om*/
    return new FixedBoostValueSource(field, fieldValueSource, positions);
}

From source file:org.vootoo.search.function.RandomValueSourceParser.java

License:Apache License

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    int max = Integer.MAX_VALUE;
    Long seed = null;/*from   ww  w  .j a va2  s .  c  o m*/
    if (fp.hasMoreArguments()) {
        max = fp.parseInt();
    }
    if (fp.hasMoreArguments()) {
        seed = parseLong(fp);
    }
    return new RandomValueSource(max, seed);
}