本文整理汇总了Java中org.apache.solr.search.QueryParsing类的典型用法代码示例。如果您正苦于以下问题:Java QueryParsing类的具体用法?Java QueryParsing怎么用?Java QueryParsing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryParsing类属于org.apache.solr.search包,在下文中一共展示了QueryParsing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: olderDocumentsExists
import org.apache.solr.search.QueryParsing; //导入依赖的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: parse
import org.apache.solr.search.QueryParsing; //导入依赖的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);
}
示例3: FacetBase
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
public FacetBase(ResponseBuilder rb, String facetType, String facetStr) {
this.facetType = facetType;
this.facetStr = facetStr;
try {
this.localParams = QueryParsing.getLocalParams(facetStr,
rb.req.getParams());
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
this.facetOn = facetStr;
this.key = facetStr;
if (localParams != null) {
// remove local params unless it's a query
if (!facetType.equals(FacetParams.FACET_QUERY)) {
facetOn = localParams.get(CommonParams.VALUE);
key = facetOn;
}
key = localParams.get(CommonParams.OUTPUT_KEY, key);
}
}
示例4: prepare
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
SolrParams params = rb.req.getParams();
rb.doHighlights = highlighter.isHighlightingEnabled(params);
if(rb.doHighlights){
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);
}
}
}
}
示例5: doStandardQueryDebug
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
public static void doStandardQueryDebug(
SolrQueryRequest req,
String userQuery,
Query query,
boolean dbgQuery,
NamedList dbg)
{
if (dbgQuery) {
/* userQuery may have been pre-processed .. expose that */
dbg.add("rawquerystring", req.getParams().get(CommonParams.Q));
dbg.add("querystring", userQuery);
/* QueryParsing.toString isn't perfect, use it to see converted
* values, use regular toString to see any attributes of the
* underlying Query it may have missed.
*/
dbg.add("parsedquery", QueryParsing.toString(query, req.getSchema()));
dbg.add("parsedquery_toString", query.toString());
}
}
示例6: doSimpleQuery
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
/**
* Executes a basic query
*/
public static DocList doSimpleQuery(String sreq,
SolrQueryRequest req,
int start, int limit) throws IOException {
List<String> commands = StrUtils.splitSmart(sreq,';');
String qs = commands.size() >= 1 ? commands.get(0) : "";
try {
Query query = QParser.getParser(qs, null, req).getQuery();
// If the first non-query, non-filter command is a simple sort on an indexed field, then
// we can use the Lucene sort ability.
Sort sort = null;
if (commands.size() >= 2) {
sort = QueryParsing.parseSortSpec(commands.get(1), req).getSort();
}
DocList results = req.getSearcher().getDocList(query,(DocSet)null, sort, start, limit);
return results;
} catch (SyntaxError e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing query: " + qs);
}
}
示例7: getSort
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
/**
* Determines the correct Sort based on the request parameter "sort"
*
* @return null if no sort is specified.
*/
public static Sort getSort(SolrQueryRequest req) {
String sort = req.getParams().get(CommonParams.SORT);
if (null == sort || sort.equals("")) {
return null;
}
SolrException sortE = null;
Sort ss = null;
try {
ss = QueryParsing.parseSortSpec(sort, req).getSort();
} catch (SolrException e) {
sortE = e;
}
if ((null == ss) || (null != sortE)) {
/* we definitely had some sort of sort string from the user,
* but no SortSpec came out of it
*/
SolrCore.log.warn("Invalid sort \""+sort+"\" was specified, ignoring", sortE);
return null;
}
return ss;
}
示例8: parse
import org.apache.solr.search.QueryParsing; //导入依赖的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;
}
示例9: parse
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Query parse() throws SyntaxError {
Method method = Method.valueOf(localParams.get(METHOD, Method.termsFilter.name()));
JoinSpec<T> js = JoinSpec.parse(localParams.get(QueryParsing.V));
Iterator<T> it = js.iterator(this);
if (joinField == null) {
throw new Exception("No XJoin component referenced by query");
}
FieldType ft = req.getSchema().getFieldTypeNoEx(joinField);
Iterator<BytesRef> bytesRefs = new TransformIterator(it, transformer(ft));
if (! bytesRefs.hasNext()) {
return new BooleanQuery(); // matches nothing
}
return new SolrConstantScoreQuery(method.makeFilter(joinField, bytesRefs));
}
示例10: parse
import org.apache.solr.search.QueryParsing; //导入依赖的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);
}
示例11: parse
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Query parse() throws SyntaxError {
Method method = Method.valueOf(localParams.get(METHOD, Method.termsFilter.name()));
JoinSpec<T> js = JoinSpec.parse(localParams.get(QueryParsing.V));
Iterator<T> it = js.iterator(this);
if (joinField == null) {
throw new Exception("No XJoin component referenced by query");
}
FieldType ft = req.getSchema().getFieldTypeNoEx(joinField);
Iterator<BytesRef> bytesRefs = new TransformIterator(it, transformer(ft));
if (! bytesRefs.hasNext()) {
return new BooleanQuery.Builder().build(); // matches nothing
}
Query query = method.makeQuery(joinField, bytesRefs);
return new SolrConstantScoreQuery(new QueryWrapperFilter(query));
}
示例12: initialiseParameters
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Override
public void initialiseParameters(SolrParams localParams) throws SyntaxError {
getLogger().trace("Initialising parameters...");
if (localParams == null) {
throw new SyntaxError("Missing facet tree parameters");
}
// Initialise the node field - REQUIRED
nodeField = localParams.get(FacetTreeParameters.NODE_FIELD_PARAM);
if (StringUtils.isBlank(nodeField)) {
// Not specified in localParams - use the key value instead
nodeField = localParams.get(QueryParsing.V);
// If still blank, we have a problem
if (StringUtils.isBlank(nodeField)) {
throw new SyntaxError("No node field defined in " + localParams);
}
}
// Initialise the optional fields
labelField = localParams.get(FacetTreeParameters.LABEL_FIELD_PARAM, null);
}
示例13: testThatPfIsAppliedOnlyToExistingField
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Test
public void testThatPfIsAppliedOnlyToExistingField() throws Exception {
String q = "a b c d";
SolrQueryRequest req = req("q", q,
DisMaxParams.QF, "f1 f2",
DisMaxParams.MM, "3",
QueryParsing.OP, "OR",
DisMaxParams.PF, "f3^2 f40^0.5",
"defType", "querqy",
"debugQuery", "true"
);
// f4 doesn't exist
assertQ("wrong ps",
req,
"//str[@name='parsedquery'][contains(.,'PhraseQuery(f3:\"a b c d\")^2.0')]",
"//str[@name='parsedquery'][not(contains(.,'PhraseQuery(f40:\"a b c d\")^0.5'))]");
req.close();
}
示例14: testThatMatchAllDoesNotThrowException
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Test
public void testThatMatchAllDoesNotThrowException() throws Exception {
String q = "*:*";
SolrQueryRequest req = req("q", q,
DisMaxParams.QF, "f1 f2",
DisMaxParams.MM, "3",
QueryParsing.OP, "OR",
DisMaxParams.PF, "f3^2 f4^0.5",
"defType", "querqy",
"debugQuery", "true"
);
assertQ("Matchall fails",
req,
"//str[@name='parsedquery'][contains(.,'*:*')]",
"//result[@name='response' and @numFound='9']"
);
req.close();
}
示例15: testThatPfIsAppliedOnlyToFieldsWithTermPositions
import org.apache.solr.search.QueryParsing; //导入依赖的package包/类
@Test
public void testThatPfIsAppliedOnlyToFieldsWithTermPositions() throws Exception {
String q = "a b c d";
SolrQueryRequest req = req("q", q,
DisMaxParams.QF, "f1 f2",
DisMaxParams.MM, "3",
QueryParsing.OP, "OR",
"defType", "querqy",
"debugQuery", "true",
DisMaxParams.PF, "f1^1.2 str^2 f_no_tfp^0.5");
// str is a string field
// f_no_tfp / f_no_tp don't have term positions
assertQ("wrong ps2",
req,
"//str[@name='parsedquery'][contains(.,'PhraseQuery(f1:\"a b c d\")^1.2')]",
"//str[@name='parsedquery'][not(contains(.,'PhraseQuery(str:\"a b c d\")^2.0'))]",
"//str[@name='parsedquery'][not(contains(.,'PhraseQuery(f_no_tfp:\"a b c d\")^0.5'))]",
"//str[@name='parsedquery'][not(contains(.,'PhraseQuery(f_no_tp:\"a b c d\")^0.5'))]");
req.close();
}