本文整理汇总了Java中org.apache.solr.search.QParser.getQuery方法的典型用法代码示例。如果您正苦于以下问题:Java QParser.getQuery方法的具体用法?Java QParser.getQuery怎么用?Java QParser.getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.search.QParser
的用法示例。
在下文中一共展示了QParser.getQuery方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: olderDocumentsExists
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
/**
* 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;
}
示例2: getQuery
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
private Query getQuery(DeleteUpdateCommand cmd) {
Query q;
try {
// move this higher in the stack?
QParser parser = QParser.getParser(cmd.getQuery(), "lucene", 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 bq = new BooleanQuery();
bq.add(q, Occur.MUST);
SchemaField sf = ulog.getVersionInfo().getVersionField();
ValueSource vs = sf.getType().getValueSource(sf, null);
ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, null, Long.toString(Math.abs(cmd.getVersion())), true, true);
FunctionRangeQuery range = new FunctionRangeQuery(filt);
bq.add(range, Occur.MUST);
q = bq;
}
return q;
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
示例3: parse
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
@Override
public Query parse() throws SyntaxError {
String filter = localParams.get(getParentFilterLocalParamName());
QParser parentParser = subQuery(filter, null);
Query parentQ = parentParser.getQuery();
String queryText = localParams.get(QueryParsing.V);
// there is no child query, return parent filter from cache
if (queryText == null || queryText.length()==0) {
SolrConstantScoreQuery wrapped = new SolrConstantScoreQuery(getFilter(parentQ));
wrapped.setCache(false);
return wrapped;
}
QParser childrenParser = subQuery(queryText, null);
Query childrenQuery = childrenParser.getQuery();
return createQuery(parentQ, childrenQuery);
}
示例4: parse
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
@Override
public Query parse() throws SyntaxError {
SolrParams localParams = getLocalParams();
SolrParams params = getParams();
SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);
QParser baseParser = subQuery(solrParams.get(QueryParsing.V), null);
Query startNodesQuery = baseParser.getQuery();
String fromField = localParams.get("from", "node_id");
String toField = localParams.get("to", "edge_ids");
QParser traversalBaseParser = subQuery(localParams.get("traversalFilter"), null);
Query traversalFilter = traversalBaseParser.getQuery();
// TODO: un-invert this logic
boolean onlyLeafNodes = Boolean.valueOf(localParams.get("returnOnlyLeaf", "false"));
boolean returnStartNodes = Boolean.valueOf(localParams.get("returnRoot", "true"));
int maxDepth = Integer.valueOf(localParams.get("maxDepth", "-1"));
GraphQuery gq = new GraphQuery(startNodesQuery, fromField, toField, traversalFilter);
gq.setMaxDepth(maxDepth);
gq.setOnlyLeafNodes(onlyLeafNodes);
gq.setReturnStartNodes(returnStartNodes);
return gq;
}
示例5: parse
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
@Override
public Query parse() throws SyntaxError {
if (localParams == null) {
throw new SyntaxError ("join query parser must be invoked using localParams");
}
String filter = localParams.get(getParentFilterLocalParamName());
QParser parentParser = subQuery(filter, null);
Query parentQ = parentParser.getQuery();
String queryText = localParams.get(QueryParsing.V);
// there is no child query, return parent filter from cache
if (queryText == null || queryText.length()==0) {
SolrConstantScoreQuery wrapped = new SolrConstantScoreQuery(getFilter(parentQ));
wrapped.setCache(false);
return wrapped;
}
QParser childrenParser = subQuery(queryText, null);
Query childrenQuery = childrenParser.getQuery();
return createQuery(parentQ, childrenQuery);
}
示例6: parseQueryString
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
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 + ".");
}
}
示例7: getLocalParams
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
protected Query getLocalParams(String qfield, String lparams) throws SyntaxError {
QParser nested = parser.subQuery(lparams, null);
return nested.getQuery();
}
示例8: parseQuery
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
public static Query parseQuery(SolrQueryRequest request, String q) throws SyntaxError {
final SolrParams params = request.getParams();
String defType = params.get(QueryParsing.DEFTYPE, EDISMAX);
QParser parser = QParser.getParser(q, defType, request);
return parser.getQuery();
}
示例9: prepare
import org.apache.solr.search.QParser; //导入方法依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException
{
SolrQueryRequest req = rb.req;
SolrParams params = req.getParams();
if (!params.getBool(COMPONENT_NAME, true)) {
return;
}
SolrQueryResponse rsp = rb.rsp;
// Set field flags
ReturnFields returnFields = new SolrReturnFields( req );
rsp.setReturnFields( returnFields );
int flags = 0;
if (returnFields.wantsScore()) {
flags |= SolrIndexSearcher.GET_SCORES;
}
rb.setFieldFlags( flags );
String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);
// get it from the response builder to give a different component a chance
// to set it.
String queryString = rb.getQueryString();
if (queryString == null) {
// this is the normal way it's set.
queryString = params.get( CommonParams.Q );
rb.setQueryString(queryString);
}
try {
QParser parser = QParser.getParser(rb.getQueryString(), defType, req);
Query q = parser.getQuery();
if (q == null) {
// normalize a null query to a query that matches nothing
q = new BooleanQuery();
}
rb.setQuery( q );
rb.setSortSpec( parser.getSort(true) );
rb.setQparser(parser);
final String cursorStr = rb.req.getParams().get(CursorMarkParams.CURSOR_MARK_PARAM);
if (null != cursorStr) {
final CursorMark cursorMark = new CursorMark(rb.req.getSchema(),
rb.getSortSpec());
cursorMark.parseSerializedTotem(cursorStr);
rb.setCursorMark(cursorMark);
}
String[] fqs = req.getParams().getParams(CommonParams.FQ);
if (fqs!=null && fqs.length!=0) {
List<Query> filters = rb.getFilters();
// if filters already exists, make a copy instead of modifying the original
filters = filters == null ? new ArrayList<Query>(fqs.length) : new ArrayList<Query>(filters);
for (String fq : fqs) {
if (fq != null && fq.trim().length()!=0) {
QParser fqp = QParser.getParser(fq, null, req);
filters.add(fqp.getQuery());
}
}
// only set the filters if they are not empty otherwise
// fq=&someotherParam= will trigger all docs filter for every request
// if filter cache is disabled
if (!filters.isEmpty()) {
rb.setFilters( filters );
}
}
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
if (params.getBool(GroupParams.GROUP, false)) {
prepareGrouping(rb);
}
}