use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.
the class FacetProcessor method evalFilters.
private void evalFilters() throws IOException {
if (freq.domain.filters == null || freq.domain.filters.isEmpty())
return;
List<Query> qlist = new ArrayList<>(freq.domain.filters.size());
// TODO: prevent parsing filters each time!
for (Object rawFilter : freq.domain.filters) {
if (rawFilter instanceof String) {
QParser parser = null;
try {
parser = QParser.getParser((String) rawFilter, fcontext.req);
parser.setIsFilter(true);
Query symbolicFilter = parser.getQuery();
qlist.add(symbolicFilter);
} catch (SyntaxError syntaxError) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, syntaxError);
}
} else if (rawFilter instanceof Map) {
Map<String, Object> m = (Map<String, Object>) rawFilter;
String type;
Object args;
if (m.size() == 1) {
Map.Entry<String, Object> entry = m.entrySet().iterator().next();
type = entry.getKey();
args = entry.getValue();
} else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't convert map to query:" + rawFilter);
}
if (!"param".equals(type)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown type. Can't convert map to query:" + rawFilter);
}
String tag;
if (!(args instanceof String)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't retrieve non-string param:" + args);
}
tag = (String) args;
String[] qstrings = fcontext.req.getParams().getParams(tag);
if (qstrings != null) {
for (String qstring : qstrings) {
QParser parser = null;
try {
parser = QParser.getParser((String) qstring, fcontext.req);
parser.setIsFilter(true);
Query symbolicFilter = parser.getQuery();
qlist.add(symbolicFilter);
} catch (SyntaxError syntaxError) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, syntaxError);
}
}
}
} else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Bad query (expected a string):" + rawFilter);
}
}
this.filter = fcontext.searcher.getDocSet(qlist);
}
use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.
the class DirectUpdateHandler2 method getQuery.
private Query getQuery(DeleteUpdateCommand cmd) {
Query q;
try {
// move this higher in the stack?
QParser parser = QParser.getParser(cmd.getQuery(), cmd.req);
q = parser.getQuery();
q = QueryUtils.makeQueryable(q);
// Make sure not to delete newer versions
if (ulog != null && cmd.getVersion() != 0 && cmd.getVersion() != -Long.MAX_VALUE) {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
bq.add(q, Occur.MUST);
SchemaField sf = ulog.getVersionInfo().getVersionField();
ValueSource vs = sf.getType().getValueSource(sf, null);
ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, Long.toString(Math.abs(cmd.getVersion())), null, true, true);
FunctionRangeQuery range = new FunctionRangeQuery(filt);
// formulated in the "MUST_NOT" sense so we can delete docs w/o a version (some tests depend on this...)
bq.add(range, Occur.MUST_NOT);
q = bq.build();
}
return q;
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.
the class FacetingAccumulator method processQueryFacets.
/**
* Initiates the collecting of query facets
* @param filter the base filter to work against
* @throws IOException if searching failed
*/
public void processQueryFacets(final Filter filter) throws IOException {
for (QueryFacetRequest qfr : queryFacets) {
for (String query : qfr.getQueries()) {
if (query.contains(AnalyticsParams.RESULT) && !query.contains(AnalyticsParams.QUERY_RESULT)) {
try {
String[] pivotStr = ExpressionFactory.getArguments(query.substring(query.indexOf('(') + 1, query.lastIndexOf(')')).trim());
if (pivotStr.length == 1) {
query = getResult(pivotStr[0]);
} else if (pivotStr.length == 3) {
query = getResult(pivotStr[0], pivotStr[1], pivotStr[2]);
} else {
throw new SolrException(ErrorCode.BAD_REQUEST, "Result request " + query + " has an invalid amount of arguments.");
}
} catch (IndexOutOfBoundsException e) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Result request " + query + " is invalid. Lacks parentheses.", e);
}
} else if (query.contains(AnalyticsParams.QUERY_RESULT)) {
try {
String[] pivotStr = ExpressionFactory.getArguments(query.substring(query.indexOf('(') + 1, query.lastIndexOf(')')).trim());
if (pivotStr.length == 3) {
query = getQueryResult(qfr.getName(), pivotStr[0], pivotStr[1], pivotStr[2]);
} else {
throw new SolrException(ErrorCode.BAD_REQUEST, "Result request " + query + " has an invalid amount of arguments.");
}
} catch (IndexOutOfBoundsException e) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Result request " + query + " is invalid. Lacks parentheses.", e);
}
}
QueryFacetAccumulator qAcc = new QueryFacetAccumulator(this, qfr.getName(), query);
final Query q;
try {
q = QParser.getParser(query, queryRequest).getQuery();
} catch (SyntaxError e) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid query '" + query + "'", e);
}
// The searcher sends docIds to the QueryFacetAccumulator which forwards
// them to <code>collectQuery()</code> in this class for collection.
Query filtered = new BooleanQuery.Builder().add(q, Occur.MUST).add(filter, Occur.FILTER).build();
searcher.search(filtered, qAcc);
computeQueryFacet(qfr.getName());
queryCount++;
}
}
}
use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.
the class HighlightComponent method prepare.
@Override
public void prepare(ResponseBuilder rb) throws IOException {
SolrParams params = rb.req.getParams();
rb.doHighlights = solrConfigHighlighter.isHighlightingEnabled(params);
if (rb.doHighlights) {
rb.setNeedDocList(true);
String hlq = params.get(HighlightParams.Q);
String hlparser = Objects.firstNonNull(params.get(HighlightParams.QPARSER), params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE));
if (hlq != null) {
try {
QParser parser = QParser.getParser(hlq, hlparser, rb.req);
rb.setHighlightQuery(parser.getHighlightQuery());
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
}
}
use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.
the class ClassificationUpdateProcessorFactory method getInstance.
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
String trainingFilterQueryString = (params.get(KNN_FILTER_QUERY));
try {
if (trainingFilterQueryString != null && !trainingFilterQueryString.isEmpty()) {
Query trainingFilterQuery = this.parseFilterQuery(trainingFilterQueryString, params, req);
classificationParams.setTrainingFilterQuery(trainingFilterQuery);
}
} catch (SyntaxError | RuntimeException syntaxError) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Classification UpdateProcessor Training Filter Query: '" + trainingFilterQueryString + "' is not supported", syntaxError);
}
IndexSchema schema = req.getSchema();
IndexReader indexReader = req.getSearcher().getIndexReader();
return new ClassificationUpdateProcessor(classificationParams, next, indexReader, schema);
}
Aggregations