Search in sources :

Example 1 with SyntaxError

use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.

the class QueryParser method Term.

public final Query Term(String field) throws ParseException, SyntaxError {
    Token term, boost = null, fuzzySlop = null, goop1, goop2;
    boolean prefix = false;
    boolean wildcard = false;
    boolean fuzzy = false;
    boolean regexp = false;
    boolean startInc = false;
    boolean endInc = false;
    Query q;
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case BAREOPER:
        case STAR:
        case TERM:
        case PREFIXTERM:
        case WILDTERM:
        case REGEXPTERM:
        case NUMBER:
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case TERM:
                    term = jj_consume_token(TERM);
                    break;
                case STAR:
                    term = jj_consume_token(STAR);
                    wildcard = true;
                    break;
                case PREFIXTERM:
                    term = jj_consume_token(PREFIXTERM);
                    prefix = true;
                    break;
                case WILDTERM:
                    term = jj_consume_token(WILDTERM);
                    wildcard = true;
                    break;
                case REGEXPTERM:
                    term = jj_consume_token(REGEXPTERM);
                    regexp = true;
                    break;
                case NUMBER:
                    term = jj_consume_token(NUMBER);
                    break;
                case BAREOPER:
                    term = jj_consume_token(BAREOPER);
                    term.image = term.image.substring(0, 1);
                    break;
                default:
                    jj_la1[12] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                case FUZZY_SLOP:
                    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                        case CARAT:
                            jj_consume_token(CARAT);
                            boost = jj_consume_token(NUMBER);
                            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                                case FUZZY_SLOP:
                                    fuzzySlop = jj_consume_token(FUZZY_SLOP);
                                    fuzzy = true;
                                    break;
                                default:
                                    jj_la1[13] = jj_gen;
                                    ;
                            }
                            break;
                        case FUZZY_SLOP:
                            fuzzySlop = jj_consume_token(FUZZY_SLOP);
                            fuzzy = true;
                            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                                case CARAT:
                                    jj_consume_token(CARAT);
                                    boost = jj_consume_token(NUMBER);
                                    break;
                                default:
                                    jj_la1[14] = jj_gen;
                                    ;
                            }
                            break;
                        default:
                            jj_la1[15] = jj_gen;
                            jj_consume_token(-1);
                            throw new ParseException();
                    }
                    break;
                default:
                    jj_la1[16] = jj_gen;
                    ;
            }
            q = handleBareTokenQuery(getField(field), term, fuzzySlop, prefix, wildcard, fuzzy, regexp);
            break;
        case RANGEIN_START:
        case RANGEEX_START:
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case RANGEIN_START:
                    jj_consume_token(RANGEIN_START);
                    startInc = true;
                    break;
                case RANGEEX_START:
                    jj_consume_token(RANGEEX_START);
                    break;
                default:
                    jj_la1[17] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case RANGE_GOOP:
                    goop1 = jj_consume_token(RANGE_GOOP);
                    break;
                case RANGE_QUOTED:
                    goop1 = jj_consume_token(RANGE_QUOTED);
                    break;
                case RANGE_TO:
                    goop1 = jj_consume_token(RANGE_TO);
                    break;
                default:
                    jj_la1[18] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
            jj_consume_token(RANGE_TO);
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case RANGE_GOOP:
                    goop2 = jj_consume_token(RANGE_GOOP);
                    break;
                case RANGE_QUOTED:
                    goop2 = jj_consume_token(RANGE_QUOTED);
                    break;
                case RANGE_TO:
                    goop2 = jj_consume_token(RANGE_TO);
                    break;
                default:
                    jj_la1[19] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case RANGEIN_END:
                    jj_consume_token(RANGEIN_END);
                    endInc = true;
                    break;
                case RANGEEX_END:
                    jj_consume_token(RANGEEX_END);
                    break;
                default:
                    jj_la1[20] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                    jj_consume_token(CARAT);
                    boost = jj_consume_token(NUMBER);
                    break;
                default:
                    jj_la1[21] = jj_gen;
                    ;
            }
            boolean startOpen = false;
            boolean endOpen = false;
            if (goop1.kind == RANGE_QUOTED) {
                goop1.image = goop1.image.substring(1, goop1.image.length() - 1);
            } else if ("*".equals(goop1.image)) {
                startOpen = true;
            }
            if (goop2.kind == RANGE_QUOTED) {
                goop2.image = goop2.image.substring(1, goop2.image.length() - 1);
            } else if ("*".equals(goop2.image)) {
                endOpen = true;
            }
            q = getRangeQuery(getField(field), startOpen ? null : discardEscapeChar(goop1.image), endOpen ? null : discardEscapeChar(goop2.image), startInc, endInc);
            break;
        case QUOTED:
            term = jj_consume_token(QUOTED);
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                case FUZZY_SLOP:
                    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                        case CARAT:
                            jj_consume_token(CARAT);
                            boost = jj_consume_token(NUMBER);
                            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                                case FUZZY_SLOP:
                                    fuzzySlop = jj_consume_token(FUZZY_SLOP);
                                    fuzzy = true;
                                    break;
                                default:
                                    jj_la1[22] = jj_gen;
                                    ;
                            }
                            break;
                        case FUZZY_SLOP:
                            fuzzySlop = jj_consume_token(FUZZY_SLOP);
                            fuzzy = true;
                            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                                case CARAT:
                                    jj_consume_token(CARAT);
                                    boost = jj_consume_token(NUMBER);
                                    break;
                                default:
                                    jj_la1[23] = jj_gen;
                                    ;
                            }
                            break;
                        default:
                            jj_la1[24] = jj_gen;
                            jj_consume_token(-1);
                            throw new ParseException();
                    }
                    break;
                default:
                    jj_la1[25] = jj_gen;
                    ;
            }
            q = handleQuotedTerm(getField(field), term, fuzzySlop);
            break;
        default:
            jj_la1[26] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    {
        if (true)
            return handleBoost(q, boost);
    }
    throw new Error("Missing return statement in function");
}
Also used : Query(org.apache.lucene.search.Query) SyntaxError(org.apache.solr.search.SyntaxError)

Example 2 with SyntaxError

use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.

the class QueryParser method Clause.

public final Query Clause(String field) throws ParseException, SyntaxError {
    Query q;
    Token fieldToken = null, boost = null;
    Token localParams = null;
    int flags = 0;
    if (jj_2_3(2)) {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case TERM:
                fieldToken = jj_consume_token(TERM);
                jj_consume_token(COLON);
                field = discardEscapeChar(fieldToken.image);
                break;
            case STAR:
                jj_consume_token(STAR);
                jj_consume_token(COLON);
                field = "*";
                break;
            default:
                jj_la1[7] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
        }
    } else {
        ;
    }
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case BAREOPER:
        case STAR:
        case QUOTED:
        case TERM:
        case PREFIXTERM:
        case WILDTERM:
        case REGEXPTERM:
        case RANGEIN_START:
        case RANGEEX_START:
        case NUMBER:
            q = Term(field);
            break;
        case LPAREN:
            jj_consume_token(LPAREN);
            q = Query(field);
            jj_consume_token(RPAREN);
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                    jj_consume_token(CARAT);
                    boost = jj_consume_token(NUMBER);
                    break;
                default:
                    jj_la1[8] = jj_gen;
                    ;
            }
            break;
        case FILTER:
            jj_consume_token(FILTER);
            flags = startFilter();
            q = Query(field);
            jj_consume_token(RPAREN);
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                    jj_consume_token(CARAT);
                    boost = jj_consume_token(NUMBER);
                    break;
                default:
                    jj_la1[9] = jj_gen;
                    ;
            }
            q = getFilter(q);
            restoreFlags(flags);
            break;
        case LPARAMS:
            localParams = jj_consume_token(LPARAMS);
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case CARAT:
                    jj_consume_token(CARAT);
                    boost = jj_consume_token(NUMBER);
                    break;
                default:
                    jj_la1[10] = jj_gen;
                    ;
            }
            q = getLocalParams(field, localParams.image);
            break;
        default:
            jj_la1[11] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    {
        if (true)
            return handleBoost(q, boost);
    }
    throw new Error("Missing return statement in function");
}
Also used : Query(org.apache.lucene.search.Query) SyntaxError(org.apache.solr.search.SyntaxError)

Example 3 with SyntaxError

use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.

the class GeoDistValueSourceParser method parse.

@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
    // TODO: dispatch through SpatialQueryable in the future?
    //note: parseValueSourceList can't handle a field reference to an AbstractSpatialFieldType,
    // so those fields are expressly handled via sfield=
    List<ValueSource> sources = fp.parseValueSourceList();
    // "m" is a multi-value source, "x" is a single-value source
    // allow (m,m) (m,x,x) (x,x,m) (x,x,x,x)
    // if not enough points are present, "pt" will be checked first, followed by "sfield".
    MultiValueSource mv1 = null;
    MultiValueSource mv2 = null;
    if (sources.size() == 0) {
    // nothing to do now
    } else if (sources.size() == 1) {
        ValueSource vs = sources.get(0);
        if (!(vs instanceof MultiValueSource)) {
            throw new SyntaxError("geodist - invalid parameters:" + sources);
        }
        mv1 = (MultiValueSource) vs;
    } else if (sources.size() == 2) {
        ValueSource vs1 = sources.get(0);
        ValueSource vs2 = sources.get(1);
        if (vs1 instanceof MultiValueSource && vs2 instanceof MultiValueSource) {
            mv1 = (MultiValueSource) vs1;
            mv2 = (MultiValueSource) vs2;
        } else {
            mv1 = makeMV(sources, sources);
        }
    } else if (sources.size() == 3) {
        ValueSource vs1 = sources.get(0);
        ValueSource vs2 = sources.get(1);
        if (vs1 instanceof MultiValueSource) {
            // (m,x,x)
            mv1 = (MultiValueSource) vs1;
            mv2 = makeMV(sources.subList(1, 3), sources);
        } else {
            // (x,x,m)
            mv1 = makeMV(sources.subList(0, 2), sources);
            vs1 = sources.get(2);
            if (!(vs1 instanceof MultiValueSource)) {
                throw new SyntaxError("geodist - invalid parameters:" + sources);
            }
            mv2 = (MultiValueSource) vs1;
        }
    } else if (sources.size() == 4) {
        mv1 = makeMV(sources.subList(0, 2), sources);
        mv2 = makeMV(sources.subList(2, 4), sources);
    } else if (sources.size() > 4) {
        throw new SyntaxError("geodist - invalid parameters:" + sources);
    }
    if (mv1 == null) {
        mv1 = parsePoint(fp);
        mv2 = parseSfield(fp);
    } else if (mv2 == null) {
        mv2 = parsePoint(fp);
        if (mv2 == null)
            mv2 = parseSfield(fp);
    }
    if (mv1 == null || mv2 == null) {
        throw new SyntaxError("geodist - not enough parameters:" + sources);
    }
    // We have all the parameters at this point, now check if one of the points is constant
    //latLon
    double[] constants;
    constants = getConstants(mv1);
    MultiValueSource other = mv2;
    if (constants == null) {
        constants = getConstants(mv2);
        other = mv1;
    }
    // sfield can only be in mv2, according to the logic above
    if (mv2 instanceof SpatialStrategyMultiValueSource) {
        if (constants == null)
            throw new SyntaxError("When using AbstractSpatialFieldType (e.g. RPT not LatLonType)," + " the point must be supplied as constants");
        // note: uses Haversine by default but can be changed via distCalc=...
        SpatialStrategy strategy = ((SpatialStrategyMultiValueSource) mv2).strategy;
        DistanceUnits distanceUnits = ((SpatialStrategyMultiValueSource) mv2).distanceUnits;
        Point queryPoint = strategy.getSpatialContext().makePoint(constants[1], constants[0]);
        return strategy.makeDistanceValueSource(queryPoint, distanceUnits.multiplierFromDegreesToThisUnit());
    }
    if (constants != null && other instanceof VectorValueSource) {
        return new HaversineConstFunction(constants[0], constants[1], (VectorValueSource) other);
    }
    return new HaversineFunction(mv1, mv2, DistanceUtils.EARTH_MEAN_RADIUS_KM, true);
}
Also used : SyntaxError(org.apache.solr.search.SyntaxError) VectorValueSource(org.apache.lucene.queries.function.valuesource.VectorValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) MultiValueSource(org.apache.lucene.queries.function.valuesource.MultiValueSource) VectorValueSource(org.apache.lucene.queries.function.valuesource.VectorValueSource) DistanceUnits(org.apache.solr.util.DistanceUnits) Point(org.locationtech.spatial4j.shape.Point) MultiValueSource(org.apache.lucene.queries.function.valuesource.MultiValueSource) SpatialStrategy(org.apache.lucene.spatial.SpatialStrategy)

Example 4 with SyntaxError

use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.

the class GeoDistValueSourceParser method makeMV.

/** make a MultiValueSource from two non MultiValueSources */
private VectorValueSource makeMV(List<ValueSource> sources, List<ValueSource> orig) throws SyntaxError {
    ValueSource vs1 = sources.get(0);
    ValueSource vs2 = sources.get(1);
    if (vs1 instanceof MultiValueSource || vs2 instanceof MultiValueSource) {
        throw new SyntaxError("geodist - invalid parameters:" + orig);
    }
    return new VectorValueSource(sources);
}
Also used : SyntaxError(org.apache.solr.search.SyntaxError) VectorValueSource(org.apache.lucene.queries.function.valuesource.VectorValueSource) ValueSource(org.apache.lucene.queries.function.ValueSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) MultiValueSource(org.apache.lucene.queries.function.valuesource.MultiValueSource) VectorValueSource(org.apache.lucene.queries.function.valuesource.VectorValueSource) MultiValueSource(org.apache.lucene.queries.function.valuesource.MultiValueSource)

Example 5 with SyntaxError

use of org.apache.solr.search.SyntaxError in project lucene-solr by apache.

the class FacetProcessor method handleBlockJoin.

// returns "true" if filters were applied to fcontext.base already
private boolean handleBlockJoin() throws IOException {
    boolean appliedFilters = false;
    if (!(freq.domain.toChildren || freq.domain.toParent))
        return appliedFilters;
    // TODO: avoid query parsing per-bucket somehow...
    String parentStr = freq.domain.parents;
    Query parentQuery;
    try {
        QParser parser = QParser.getParser(parentStr, fcontext.req);
        parser.setIsFilter(true);
        parentQuery = parser.getQuery();
    } catch (SyntaxError err) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing block join parent specification: " + parentStr);
    }
    BitDocSet parents = fcontext.searcher.getDocSetBits(parentQuery);
    DocSet input = fcontext.base;
    DocSet result;
    if (freq.domain.toChildren) {
        // If there are filters on this facet, then use them as acceptDocs when executing toChildren.
        // We need to remember to not redundantly re-apply these filters after.
        DocSet acceptDocs = this.filter;
        if (acceptDocs == null) {
            acceptDocs = fcontext.searcher.getLiveDocs();
        } else {
            appliedFilters = true;
        }
        result = BlockJoin.toChildren(input, parents, acceptDocs, fcontext.qcontext);
    } else {
        result = BlockJoin.toParents(input, parents, fcontext.qcontext);
    }
    fcontext.base = result;
    return appliedFilters;
}
Also used : BitDocSet(org.apache.solr.search.BitDocSet) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) SyntaxError(org.apache.solr.search.SyntaxError) QParser(org.apache.solr.search.QParser) SolrException(org.apache.solr.common.SolrException) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Aggregations

SyntaxError (org.apache.solr.search.SyntaxError)35 SolrException (org.apache.solr.common.SolrException)23 Query (org.apache.lucene.search.Query)21 QParser (org.apache.solr.search.QParser)12 ArrayList (java.util.ArrayList)10 SchemaField (org.apache.solr.schema.SchemaField)10 BooleanQuery (org.apache.lucene.search.BooleanQuery)8 SolrParams (org.apache.solr.common.params.SolrParams)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)6 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)6 IOException (java.io.IOException)5 List (java.util.List)5 NamedList (org.apache.solr.common.util.NamedList)5 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)5 Map (java.util.Map)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)4 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)4 FieldType (org.apache.solr.schema.FieldType)4 IndexSchema (org.apache.solr.schema.IndexSchema)4 DocList (org.apache.solr.search.DocList)4