List of usage examples for org.apache.solr.search FunctionQParser parseArg
public String parseArg() throws SyntaxError
From source file:alba.solr.core.DynamicValueSourceParser.java
License:Apache License
@SuppressWarnings("unchecked") public ValueSource parse(FunctionQParser fp) throws SyntaxError { String functionName;//from ww w . j a va 2s.co 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()); }/*w w w. j av a 2s .c om*/ 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:com.mysoft.b2b.solr.B258DynamicSourceParser.java
License:Open Source License
public ValueSource parse(FunctionQParser fp) throws SyntaxError { String field = fp.parseArg(); ValueSource v1 = getValueSource(fp, field); List<ValueSource> sources = fp.parseValueSourceList(); return new B258DynamicSource(sources.toArray(new ValueSource[sources.size()]), v1); }
From source file:jp.sf.fess.solr.plugin.search.WordFreqValueSourceParser.java
License:Apache License
@Override public ValueSource parse(final FunctionQParser fp) throws SyntaxError { final String field = fp.parseArg(); final String word = fp.parseArg(); final boolean normalized = !"false".equals(fp.parseArg()); return new WordFreqValueSource(field, word, normalized); }
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()); }/*from w ww .ja v a2 s . c om*/ return new LireValueSource(field, hist, maxDistance); }
From source file:org.opencommercesearch.lucene.queries.function.valuesource.BoostValueSourceParser.java
License:Apache License
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { String field = fp.parseArg(); SolrParams params = fp.getReq().getParams(); String boostId = params.get(BOOST_ID); String treatmentId = params.get(TREATMENT_ID); if (StringUtils.isNotBlank(treatmentId)) { if (log.isDebugEnabled()) { log.debug("There is treatment enabled:" + treatmentId); }/*from w w w . ja v a 2 s. co m*/ boostId += "_" + treatmentId; } SchemaField f = fp.getReq().getSchema().getField(field); ValueSource fieldValueSource = f.getType().getValueSource(f, fp); Map<String, Float> boosts = Collections.emptyMap(); if (StringUtils.isBlank(boostId)) { if (log.isDebugEnabled()) { log.debug("Missing required 'boostId', skipping boosts"); } return new BoostValueSource(field, fieldValueSource, boosts); } int queryRows = NumberUtils.toInt(params.get(CommonParams.ROWS), 0); if (queryRows == 0) { if (log.isDebugEnabled()) { log.debug("Zero rows specified for this query, boosts not needed"); } return new BoostValueSource(field, fieldValueSource, boosts); } @SuppressWarnings("unchecked") SolrCache<String, Map<String, Float>> cache = (SolrCache<String, Map<String, Float>>) fp.getReq() .getSearcher().getCache("boostCache"); return new BoostValueSource(field, fieldValueSource, loadBoosts(boostId, cache)); }
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 w w w. j a v a2s . c o m*/ return new FixedBoostValueSource(field, fieldValueSource, positions); }
From source file:org.vootoo.search.function.RandomValueSourceParser.java
License:Apache License
protected long parseLong(FunctionQParser fp) throws SyntaxError { String str = fp.parseArg(); if (fp.argWasQuoted()) throw new SyntaxError("Expected double instead of quoted string:" + str); long value = Long.parseLong(str); return value; }