Java Code Examples for org.apache.solr.search.QParser#getQuery()
The following examples show how to use
org.apache.solr.search.QParser#getQuery() .
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: 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 2
Source File: ChronixRetentionHandler.java From chronix.server with Apache License 2.0 | 6 votes |
/** * Searches the index, if older documents exists. Updates the solr query response. * * @param req - the solr query request information * @param rsp - the solr query response information * @return true if the hit count is greater zero, otherwise false * @throws SyntaxError, IOException if bad things happen */ private boolean olderDocumentsExists(String queryString, SolrQueryRequest req, SolrQueryResponse rsp) throws SyntaxError, IOException { String defType = req.getParams().get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE); QParser queryParser = QParser.getParser(queryString, defType, req); Query query = queryParser.getQuery(); TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector(); req.getSearcher().search(query, totalHitCountCollector); rsp.add("query", String.format("%s:[* TO NOW-%s]", queryField, timeSeriesAge)); rsp.add("queryTechnical", queryString); rsp.add("removedDocuments", totalHitCountCollector.getTotalHits()); return totalHitCountCollector.getTotalHits() != 0; }
Example 3
Source File: SolrQueryParserBase.java From lucene-solr with Apache License 2.0 | 5 votes |
protected Query getLocalParams(String qfield, String lparams) throws SyntaxError { if (!allowSubQueryParsing) { throw new SyntaxError("local-params subquery is disabled"); } QParser nested = parser.subQuery(lparams, null); return nested.getQuery(); }
Example 4
Source File: FacetProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
private static Query parserFilter(String rawFilter, SolrQueryRequest req) { QParser parser = null; try { parser = QParser.getParser(rawFilter, req); parser.setIsFilter(true); Query symbolicFilter = parser.getQuery(); if (symbolicFilter == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "QParser yields null, perhaps unresolved parameter reference in: "+rawFilter); } return symbolicFilter; } catch (SyntaxError syntaxError) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, syntaxError); } }
Example 5
Source File: FacetParser.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public FacetQuery parse(Object arg) throws SyntaxError { parseCommonParams(arg); String qstring = null; if (arg instanceof String) { // just the field name... qstring = (String)arg; } else if (arg instanceof Map) { @SuppressWarnings({"unchecked"}) Map<String, Object> m = (Map<String, Object>) arg; qstring = getString(m, "q", null); if (qstring == null) { qstring = getString(m, "query", null); } // OK to parse subs before we have parsed our own query? // as long as subs don't need to know about it. parseSubs( m.get("facet") ); } else if (arg != null) { // something lke json.facet.facet.query=2 throw err("Expected string/map for facet query, received " + arg.getClass().getSimpleName() + "=" + arg); } // TODO: substats that are from defaults!!! if (qstring != null) { QParser parser = QParser.getParser(qstring, getSolrRequest()); parser.setIsFilter(true); facet.q = parser.getQuery(); } return facet; }
Example 6
Source File: BJQParserTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testFiltersCache() throws SyntaxError, IOException { final String [] elFilterQuery = new String[] {"q", "{!filters param=$child.fq v=$gchq}", "child.fq", "childparent_s:e", "child.fq", "child_s:l", "gchq", "child_s:[* TO *]"}; assertQ("precondition: single doc match", req(elFilterQuery), elChild); final Query query; try(final SolrQueryRequest req = req(elFilterQuery)) { QParser parser = QParser.getParser(req.getParams().get("q"), null, req); query = parser.getQuery(); final TopDocs topDocs = req.getSearcher().search(query, 10); assertEquals(1, topDocs.totalHits.value); } assertU(adoc("id", "12275", "child_s", "l", "childparent_s", "e")); assertU(commit()); assertQ("here we rely on autowarming for cathing cache leak", //cache=false req(elFilterQuery), "//*[@numFound='2']"); try(final SolrQueryRequest req = req()) { final int count = req.getSearcher().count(query); assertEquals("expecting new doc is visible to old query", 2, count); } }
Example 7
Source File: ParseUtility.java From semantic-knowledge-graph with Apache License 2.0 | 5 votes |
public static Query parseQueryString(String qString, SolrQueryRequest req) { try { QParser parser = QParser.getParser(qString, req.getParams().get("defType"), req); return parser.getQuery(); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Syntax error in query: " + qString + "."); } }
Example 8
Source File: BlockJoinParentQParser.java From lucene-solr with Apache License 2.0 | 4 votes |
protected Query parseParentFilter() throws SyntaxError { String filter = localParams.get(getParentFilterLocalParamName()); QParser parentParser = subQuery(filter, null); Query parentQ = parentParser.getQuery(); return parentQ; }