org.apache.solr.search.QParser Java Examples
The following examples show how to use
org.apache.solr.search.QParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractQuerqyDismaxQParserPlugin.java From querqy with Apache License 2.0 | 6 votes |
@Override public final QParser createParser(final String qstr, final SolrParams localParams, final SolrParams params, SolrQueryRequest req) { if (termQueryCacheName == null) { return createParser(qstr, localParams, params, req, infoLogging, null); } else { @SuppressWarnings("unchecked") final SolrCache<CacheKey, TermQueryCacheValue> solrCache = req.getSearcher().getCache(termQueryCacheName); if (solrCache == null) { logger.warn("Missing Solr cache {}", termQueryCacheName); return createParser(qstr, localParams, params, req, infoLogging, null); } else { return createParser(qstr, localParams, params, req, infoLogging, new SolrTermQueryCacheAdapter(ignoreTermQueryCacheUpdates, solrCache)); } } }
Example #2
Source File: SortableTextField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public ValueSource getSingleValueSource(MultiValueSelector choice, SchemaField field, QParser parser) { // trivial base case if (!field.multiValued()) { // single value matches any selector return getValueSource(field, parser); } // See LUCENE-6709 if (! field.hasDocValues()) { // type defaults to docValues=true, so error msg from perspective that // either type or field must have docValues="false" throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not select '" + choice.toString() + "' value from multivalued field ("+ field.getName() +") when docValues=\"false\", field: " + field.getName()); } SortedSetSelector.Type selectorType = choice.getSortedSetSelectorType(); if (null == selectorType) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, choice.toString() + " is not a supported option for picking a single value" + " from the multivalued field: " + field.getName() + " (type: " + this.getTypeName() + ")"); } return new SortedSetFieldSource(field.getName(), selectorType); }
Example #3
Source File: LongPointField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query getPointRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) { long actualMin, actualMax; if (min == null) { actualMin = Long.MIN_VALUE; } else { actualMin = parseLongFromUser(field.getName(), min); if (!minInclusive) { if (actualMin == Long.MAX_VALUE) return new MatchNoDocsQuery(); actualMin++; } } if (max == null) { actualMax = Long.MAX_VALUE; } else { actualMax = parseLongFromUser(field.getName(), max); if (!maxInclusive) { if (actualMax == Long.MIN_VALUE) return new MatchNoDocsQuery(); actualMax--; } } return LongPoint.newRangeQuery(field.getName(), actualMin, actualMax); }
Example #4
Source File: QueryFacet.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void createFacetValueExecuters(final Filter filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> consumer) { queries.forEach( (queryName, query) -> { final Query q; try { q = QParser.getParser(query, queryRequest).getQuery(); } catch( Exception e ){ throw new SolrException(ErrorCode.BAD_REQUEST,"Invalid query '"+query+"' in query facet '" + getName() + "'",e); } // The searcher sends docIds to the QueryFacetAccumulator which forwards // them to <code>collectQuery()</code> in this class for collection. Query queryQuery = QueryUtils.combineQueryAndFilter(q, filter); ReductionDataCollection dataCol = collectionManager.newDataCollection(); reductionData.put(queryName, dataCol); consumer.accept(new FacetValueQueryExecuter(dataCol, queryQuery)); }); }
Example #5
Source File: LocalGraph.java From SolRDF with Apache License 2.0 | 6 votes |
/** * Builds a new {@link LocalGraph} with the given data. * * @param graphNode the graph name. * @param request the Solr query request. * @param response the Solr query response. * @param qparser the query parser. * @param fetchSize the fetch size that will be used in reads. * @param consumer the Graph event consumer that will be notified on relevant events. */ private LocalGraph( final Node graphNode, final SolrQueryRequest request, final SolrQueryResponse response, final QParser qparser, final int fetchSize, final GraphEventConsumer consumer) { super(graphNode, consumer, fetchSize); this.graphTermQuery = new TermQuery(new Term(Field.C, graphNodeStringified)); this.request = request; this.updateCommand = new AddUpdateCommand(request); this.updateProcessor = request.getCore().getUpdateProcessingChain(null).createProcessor(request, response); this.searcher = request.getSearcher(); this.qParser = qparser; }
Example #6
Source File: DirectUpdateHandler2.java From lucene-solr with Apache License 2.0 | 6 votes |
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); bq.add(range, Occur.MUST_NOT); // formulated in the "MUST_NOT" sense so we can delete docs w/o a version (some tests depend on this...) q = bq.build(); } return q; } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } }
Example #7
Source File: AbstractSpatialFieldType.java From lucene-solr with Apache License 2.0 | 6 votes |
protected Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) { T strategy = getStrategy(field.getName()); SolrParams localParams = parser.getLocalParams(); //See SOLR-2883 needScore String scoreParam = (localParams == null ? null : localParams.get(SCORE_PARAM)); //We get the valueSource for the score then the filter and combine them. DoubleValuesSource valueSource = getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy); if (valueSource == null) { return strategy.makeQuery(spatialArgs); //assumed constant scoring } FunctionScoreQuery functionQuery = new FunctionScoreQuery(new MatchAllDocsQuery(), valueSource); if (localParams != null && !localParams.getBool(FILTER_PARAM, true)) return functionQuery; Query filterQuery = strategy.makeQuery(spatialArgs); return new BooleanQuery.Builder() .add(functionQuery, Occur.MUST)//matches everything and provides score .add(filterQuery, Occur.FILTER)//filters (score isn't used) .build(); }
Example #8
Source File: TaggerRequestHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * The set of documents matching the provided 'fq' (filter query). Don't include deleted docs * either. If null is returned, then all docs are available. */ private Bits computeDocCorpus(SolrQueryRequest req) throws SyntaxError, IOException { final String[] corpusFilterQueries = req.getParams().getParams("fq"); final SolrIndexSearcher searcher = req.getSearcher(); final Bits docBits; if (corpusFilterQueries != null && corpusFilterQueries.length > 0) { List<Query> filterQueries = new ArrayList<Query>(corpusFilterQueries.length); for (String corpusFilterQuery : corpusFilterQueries) { QParser qParser = QParser.getParser(corpusFilterQuery, null, req); try { filterQueries.add(qParser.parse()); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } } final DocSet docSet = searcher.getDocSet(filterQueries);//hopefully in the cache docBits = docSet.getBits(); } else { docBits = searcher.getSlowAtomicReader().getLiveDocs(); } return docBits; }
Example #9
Source File: QuerqyQueryComponent.java From querqy with Apache License 2.0 | 6 votes |
@Override public void prepare(final ResponseBuilder rb) throws IOException { super.prepare(rb); QParser parser = rb.getQparser(); if (parser instanceof QuerqyDismaxQParser) { List<Query> filterQueries = ((QuerqyDismaxQParser) parser).getFilterQueries(); if ((filterQueries != null) && !filterQueries.isEmpty()) { List<Query> filters = rb.getFilters(); if (filters == null) { rb.setFilters(filterQueries); } else { filters.addAll(filterQueries); } } } }
Example #10
Source File: IntPointField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query getPointRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) { int actualMin, actualMax; if (min == null) { actualMin = Integer.MIN_VALUE; } else { actualMin = parseIntFromUser(field.getName(), min); if (!minInclusive) { if (actualMin == Integer.MAX_VALUE) return new MatchNoDocsQuery(); actualMin++; } } if (max == null) { actualMax = Integer.MAX_VALUE; } else { actualMax = parseIntFromUser(field.getName(), max); if (!maxInclusive) { if (actualMax == Integer.MIN_VALUE) return new MatchNoDocsQuery(); actualMax--; } } return IntPoint.newRangeQuery(field.getName(), actualMin, actualMax); }
Example #11
Source File: AlfrescoReRankQParserPlugin.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public Query parse() throws SyntaxError { String reRankQueryString = localParams.get("reRankQuery"); boolean scale = localParams.getBool("scale", false); QParser reRankParser = QParser.getParser(reRankQueryString, null, req); Query reRankQuery = reRankParser.parse(); int reRankDocs = localParams.getInt("reRankDocs", 200); reRankDocs = Math.max(1, reRankDocs); // double reRankWeight = localParams.getDouble("reRankWeight",2.0d); int start = params.getInt(CommonParams.START,0); int rows = params.getInt(CommonParams.ROWS,10); int length = start+rows; return new ReRankQuery(reRankQuery, reRankDocs, reRankWeight, length, scale); }
Example #12
Source File: FieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Expert: Returns the rewrite method for multiterm queries such as wildcards. * @param parser The {@link org.apache.solr.search.QParser} calling the method * @param field The {@link org.apache.solr.schema.SchemaField} of the field to search * @return A suitable rewrite method for rewriting multi-term queries to primitive queries. */ public MultiTermQuery.RewriteMethod getRewriteMethod(QParser parser, SchemaField field) { if (!field.indexed() && field.hasDocValues()) { return new DocValuesRewriteMethod(); } else { return MultiTermQuery.CONSTANT_SCORE_REWRITE; } }
Example #13
Source File: LatLonType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) { Point p1 = SpatialUtils.parsePointSolrException(part1, SpatialContext.GEO); Point p2 = SpatialUtils.parsePointSolrException(part2, SpatialContext.GEO); SchemaField latSF = subField(field, LAT, parser.getReq().getSchema()); SchemaField lonSF = subField(field, LON, parser.getReq().getSchema()); BooleanQuery.Builder result = new BooleanQuery.Builder(); // points must currently be ordered... should we support specifying any two opposite corner points? result.add(latSF.getType().getRangeQuery(parser, latSF, Double.toString(p1.getY()), Double.toString(p2.getY()), minInclusive, maxInclusive), BooleanClause.Occur.MUST); result.add(lonSF.getType().getRangeQuery(parser, lonSF, Double.toString(p1.getX()), Double.toString(p2.getX()), minInclusive, maxInclusive), BooleanClause.Occur.MUST); return result.build(); }
Example #14
Source File: CurrencyFieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) { CurrencyValue value = CurrencyValue.parse(externalVal, defaultCurrency); CurrencyValue valueDefault; valueDefault = value.convertTo(provider, defaultCurrency); return getRangeQueryInternal(parser, field, valueDefault, valueDefault, true, true); }
Example #15
Source File: IntPointField.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Query getSetQuery(QParser parser, SchemaField field, Collection<String> externalVal) { assert externalVal.size() > 0; if (!field.indexed()) { return super.getSetQuery(parser, field, externalVal); } int[] values = new int[externalVal.size()]; int i = 0; for (String val:externalVal) { values[i] = parseIntFromUser(field.getName(), val); i++; } return IntPoint.newSetQuery(field.getName(), values); }
Example #16
Source File: SparqlQParserPlugin.java From SolRDF with Apache License 2.0 | 5 votes |
@Override public QParser createParser( final String qstr, final SolrParams localParams, final SolrParams params, final SolrQueryRequest req) { return new SparqlQParser(qstr, localParams, params, req); }
Example #17
Source File: QuerySegmenterQParser.java From query-segmenter with Apache License 2.0 | 5 votes |
@Override public Query parse() throws SyntaxError { String qstr = getString(); List<TypedSegment> typedSegments = segmenter.segment(qstr); List<Query> boostQueries = new ArrayList<>(); for (TypedSegment typedSegment : typedSegments) { FieldMapping mapping = mappings.get(typedSegment.getDictionaryName()); String value = QuerySegmenterComponent.getValue(typedSegment, mapping); if (mapping.useBoostQuery) { qstr = qstr.replaceFirst(typedSegment.getSegment(), ""); String qs = String.format("%s:%s", mapping.field, value); boostQueries.add(subQuery(qs, null).getQuery()); } else { qstr = qstr.replaceFirst(typedSegment.getSegment(), String.format("%s:%s", mapping.field, value)); } } // Passing null allows to use another qparser defined with defType (like edismax) // See SOLR-2972 QParser parser = subQuery(qstr, null); BooleanQuery.Builder query = new BooleanQuery.Builder(); query.add(parser.parse(), BooleanClause.Occur.MUST); for(Query bq:boostQueries) { query.add(bq, BooleanClause.Occur.SHOULD); } return query.build(); }
Example #18
Source File: TrieField.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) { if (!field.indexed() && field.hasDocValues()) { // currently implemented as singleton range return getRangeQuery(parser, field, externalVal, externalVal, true, true); } else { return super.getFieldQuery(parser, field, externalVal); } }
Example #19
Source File: CurrencyFieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
private Query getRangeQueryInternal(QParser parser, SchemaField field, final CurrencyValue p1, final CurrencyValue p2, final boolean minInclusive, final boolean maxInclusive) { String currencyCode = (p1 != null) ? p1.getCurrencyCode() : (p2 != null) ? p2.getCurrencyCode() : defaultCurrency; // ValueSourceRangeFilter doesn't check exists(), so we have to final Query docsWithValues = new DocValuesFieldExistsQuery(getAmountField(field).getName()); final Query vsRangeFilter = new ValueSourceRangeFilter (new RawCurrencyValueSource(field, currencyCode, parser), p1 == null ? null : p1.getAmount() + "", p2 == null ? null : p2.getAmount() + "", minInclusive, maxInclusive); return new ConstantScoreQuery(new BooleanQuery.Builder() .add(docsWithValues, Occur.FILTER) .add(vsRangeFilter, Occur.FILTER).build()); }
Example #20
Source File: TestXJoinQParserPlugin.java From BioSolr with Apache License 2.0 | 5 votes |
private static Query parse(String v) throws SyntaxError { ModifiableSolrParams localParams = new ModifiableSolrParams(); localParams.add(QueryParsing.V, v); QParserPlugin qpp = core.getQueryPlugin(PARSER_NAME); QParser qp = qpp.createParser(null, localParams, null, req); return qp.parse(); }
Example #21
Source File: PointType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public ValueSource getValueSource(SchemaField field, QParser parser) { ArrayList<ValueSource> vs = new ArrayList<>(dimension); for (int i=0; i<dimension; i++) { SchemaField sub = subField(field, i, schema); vs.add(sub.getType().getValueSource(sub, parser)); } return new PointTypeValueSource(field, vs); }
Example #22
Source File: DismaxSearchEngineRequestAdapter.java From querqy with Apache License 2.0 | 5 votes |
public DismaxSearchEngineRequestAdapter(final QParser qParser, final SolrQueryRequest request, final String queryString, final SolrParams solrParams, final QuerqyParser querqyParser, final RewriteChain rewriteChain, final InfoLogging infoLogging, final TermQueryCache termQueryCache) { this.qParser = qParser; this.userQueryString = queryString; this.solrParams = solrParams; this.termQueryCache = termQueryCache; this.infoLoggingContext = solrParams.getBool(INFO_LOGGING, false) && infoLogging != null ? new InfoLoggingContext(infoLogging, this) : null; this.querqyParser = querqyParser; this.request = request; this.rewriteChain = rewriteChain; this.context = new HashMap<>(); final int ps0 = solrParams.getInt(PS, 0); final int ps2 = solrParams.getInt(PS2, ps0); final int ps3 = solrParams.getInt(PS3, ps0); final List<FieldParams> phraseFields = SolrPluginUtils .parseFieldBoostsAndSlop(solrParams.getParams(PF),0,ps0); final List<FieldParams> phraseFields2 = SolrPluginUtils .parseFieldBoostsAndSlop(solrParams.getParams(PF2),2,ps2); final List<FieldParams> phraseFields3 = SolrPluginUtils .parseFieldBoostsAndSlop(solrParams.getParams(PF3),3,ps3); allPhraseFields = new ArrayList<>(phraseFields.size() + phraseFields2.size() + phraseFields3.size()); allPhraseFields.addAll(phraseFields); allPhraseFields.addAll(phraseFields2); allPhraseFields.addAll(phraseFields3); minShouldMatch = DisMaxQParser.parseMinShouldMatch(request.getSchema(), solrParams); }
Example #23
Source File: DefaultQuerqyDismaxQParserPlugin.java From querqy with Apache License 2.0 | 5 votes |
@Override public QParser createParser(final String qstr, final SolrParams localParams, final SolrParams params, final SolrQueryRequest req, final InfoLogging infoLogging, final TermQueryCache termQueryCache) { return new QuerqyDismaxQParser(qstr, localParams, params, req, createQuerqyParser(qstr, localParams, params, req), rewriteChain, infoLogging, termQueryCache); }
Example #24
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Turns an array of query strings into a List of Query objects. * * @return null if no queries are generated */ public static List<Query> parseQueryStrings(SolrQueryRequest req, String[] queries) throws SyntaxError { if (null == queries || 0 == queries.length) return null; List<Query> out = new ArrayList<>(queries.length); for (String q : queries) { if (null != q && 0 != q.trim().length()) { out.add(QParser.getParser(q, req).getQuery()); } } return out; }
Example #25
Source File: CurrencyFieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, final boolean minInclusive, final boolean maxInclusive) { final CurrencyValue p1 = CurrencyValue.parse(part1, defaultCurrency); final CurrencyValue p2 = CurrencyValue.parse(part2, defaultCurrency); if (p1 != null && p2 != null && !p1.getCurrencyCode().equals(p2.getCurrencyCode())) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot parse range query " + part1 + " to " + part2 + ": range queries only supported when upper and lower bound have same currency."); } return getRangeQueryInternal(parser, field, p1, p2, minInclusive, maxInclusive); }
Example #26
Source File: DatasetGraphSupertypeLayer.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Builds a new Dataset graph with the given data. * * @param request the Solr query request. * @param response the Solr query response. * @param qParser the (SPARQL) query parser. * */ public DatasetGraphSupertypeLayer( final SolrQueryRequest request, final SolrQueryResponse response, final QParser qParser, final GraphEventConsumer listener) { this.request = request; this.response = response; this.qParser = qParser; this.listener = listener != null ? listener : NULL_GRAPH_EVENT_CONSUMER; }
Example #27
Source File: MLTQParserPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { if (req.getCore().getCoreDescriptor().getCloudDescriptor() != null) { return new CloudMLTQParser(qstr, localParams, params, req); } else { return new SimpleMLTQParser(qstr, localParams, params, req); } }
Example #28
Source File: FiltersQParser.java From lucene-solr with Apache License 2.0 | 5 votes |
protected BooleanQuery parseImpl() throws SyntaxError { Map<QParser, Occur> clauses = clauses(); exclude(clauses.keySet()); BooleanQuery.Builder builder = new BooleanQuery.Builder(); for (Map.Entry<QParser, Occur> clause: clauses.entrySet()) { builder.add(unwrapQuery(clause.getKey().getQuery(), clause.getValue()), clause.getValue()); } // what about empty query? return builder.build(); }
Example #29
Source File: AbstractSpatialFieldType.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public ValueSource getValueSource(SchemaField field, QParser parser) { //This is different from Solr 3 LatLonType's approach which uses the MultiValueSource concept to directly expose // the x & y pair of FieldCache value sources. throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "A ValueSource isn't directly available from this field. Instead try a query using the distance as the score."); }
Example #30
Source File: TestXJoinQParserPlugin.java From BioSolr with Apache License 2.0 | 5 votes |
private static Query parse(String v) throws SyntaxError { ModifiableSolrParams localParams = new ModifiableSolrParams(); localParams.add(QueryParsing.V, v); QParserPlugin qpp = core.getQueryPlugin(PARSER_NAME); QParser qp = qpp.createParser(null, localParams, null, req); return qp.parse(); }