SOLR-2444: implement parsing only of augmenters (localParams syntax but using [])

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1133457 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2011-06-08 16:34:33 +00:00
parent e934e3849f
commit d8928bb3c7
2 changed files with 31 additions and 13 deletions

View File

@ -88,11 +88,16 @@ public class QueryParsing {
// note to self: something needs to detect infinite recursion when parsing queries
static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params) throws ParseException {
public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params) throws ParseException {
return parseLocalParams(txt, start, target, params, LOCALPARAM_START, LOCALPARAM_END);
}
public static int parseLocalParams(String txt, int start, Map<String, String> target, SolrParams params, String startString, char endChar) throws ParseException {
int off = start;
if (!txt.startsWith(LOCALPARAM_START, off)) return start;
if (!txt.startsWith(startString, off)) return start;
StrParser p = new StrParser(txt, start, txt.length());
p.pos += 2; // skip over "{!"
p.pos += startString.length(); // skip over "{!"
for (; ;) {
/*
@ -101,13 +106,13 @@ public class QueryParsing {
}
*/
char ch = p.peek();
if (ch == LOCALPARAM_END) {
if (ch == endChar) {
return p.pos + 1;
}
String id = p.getId();
if (id.length() == 0) {
throw new ParseException("Expected identifier '}' parsing local params '" + txt + '"');
throw new ParseException("Expected ending character '" + endChar + "' parsing local params '" + txt + '"');
}
String val = null;
@ -131,7 +136,7 @@ public class QueryParsing {
if (ch == '\"' || ch == '\'') {
val = p.getQuotedString();
} else {
// read unquoted literal ended by whitespace or '}'
// read unquoted literal ended by whitespace or endChar (normally '}')
// there is no escaping.
int valStart = p.pos;
for (; ;) {
@ -139,7 +144,7 @@ public class QueryParsing {
throw new ParseException("Missing end to unquoted value starting at " + valStart + " str='" + txt + "'");
}
char c = p.val.charAt(p.pos);
if (c == LOCALPARAM_END || Character.isWhitespace(c)) {
if (c == endChar || Character.isWhitespace(c)) {
val = p.val.substring(valStart, p.pos);
break;
}
@ -157,6 +162,7 @@ public class QueryParsing {
}
}
public static String encodeLocalParamVal(String val) {
int len = val.length();
int i = 0;

View File

@ -16,17 +16,14 @@
*/
package org.apache.solr.search;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import org.apache.commons.io.FilenameUtils;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
@ -211,9 +208,24 @@ public class ReturnFields
sp.pos = start;
}
// let's try it as a function instead
String funcStr = sp.val.substring(start);
// Is it an augmenter of the form [augmenter_name foo=1 bar=myfield]?
// This is identical to localParams syntax except it uses [] instead of {!}
if (funcStr.startsWith("[")) {
Map<String,String> augmenterArgs = new HashMap<String,String>();
int end = QueryParsing.parseLocalParams(funcStr, 0, augmenterArgs, req.getParams(), "[", ']');
sp.pos += end;
String augmenterName = augmenterArgs.get("type"); // [foo] is short for [type=foo] in localParams syntax
// TODO: look up and add the augmenter. If the form was myalias:[myaugmenter], then "key" will be myalias
SolrParams augmenterParams = new MapSolrParams(augmenterArgs);
log.info("Parsed augmenter " + augmenterParams + " with alias " + key); // TODO: remove log statement after augmenter works
continue;
}
// let's try it as a function instead
QParser parser = QParser.getParser(funcStr, FunctionQParserPlugin.NAME, req);
Query q = null;
ValueSource vs = null;