org.apache.solr.parser.QueryParser Java Examples
The following examples show how to use
org.apache.solr.parser.QueryParser.
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: SearchServiceBean.java From development with Apache License 2.0 | 6 votes |
/** * Returns the Lucene query for the given locale and query text. * * @param searchString * the text query for the Lucene query parser * @param mId * the marketplace id * @param locale * the locale for the analyzer to use * @param isDefaultLocaleHandling * @return the Lucene query for the given locale and query text * @throws ParseException * in case the query cannot be parsed */ private org.apache.lucene.search.Query getLuceneQuery(String searchString, String mId, String locale, boolean isDefaultLocaleHandling) throws SyntaxError, QueryNodeException { // construct wildcard query for the actual search part org.apache.lucene.search.Query textQuery = LuceneQueryBuilder .getServiceQuery(searchString, locale, DEFAULT_LOCALE, isDefaultLocaleHandling); // build mId part TermQuery mIdQuery = new TermQuery(new Term(ProductClassBridge.MP_ID, QueryParser.escape(mId).toLowerCase())); // now construct final query BooleanQuery query = new BooleanQuery(); query.add(mIdQuery, Occur.MUST); query.add(textQuery, Occur.MUST); return query; }
Example #2
Source File: ExtendedDismaxQParser.java From lucene-solr with Apache License 2.0 | 5 votes |
public ExtendedSolrQueryParser(QParser parser, String defaultField) { super(parser, defaultField); // Respect the q.op parameter before mm will be applied later SolrParams defaultParams = SolrParams.wrapDefaults(parser.getLocalParams(), parser.getParams()); QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP)); setDefaultOperator(defaultOp); }
Example #3
Source File: DisMaxQParser.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Applies the appropriate default rules for the "mm" param based on the * effective value of the "q.op" param * * @see QueryParsing#OP * @see DisMaxParams#MM */ public static String parseMinShouldMatch(final IndexSchema schema, final SolrParams params) { org.apache.solr.parser.QueryParser.Operator op = QueryParsing.parseOP(params.get(QueryParsing.OP)); return params.get(DisMaxParams.MM, op.equals(QueryParser.Operator.AND) ? "100%" : "0%"); }
Example #4
Source File: SimpleQParserPlugin.java From lucene-solr with Apache License 2.0 | 4 votes |
public SimpleQParser (String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { super(qstr, localParams, params, req); // Some of the parameters may come in through localParams, so combine them with params. SolrParams defaultParams = SolrParams.wrapDefaults(localParams, params); // This will be used to specify what fields and boosts will be used by SimpleQueryParser. Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(defaultParams.get(SimpleParams.QF)); if (queryFields.isEmpty()) { // It qf is not specified setup up the queryFields map to use the defaultField. String defaultField = defaultParams.get(CommonParams.DF); if (defaultField == null) { // A query cannot be run without having a field or set of fields to run against. throw new IllegalStateException("Neither " + SimpleParams.QF + " nor " + CommonParams.DF + " are present."); } queryFields.put(defaultField, 1.0F); } else { for (Map.Entry<String, Float> queryField : queryFields.entrySet()) { if (queryField.getValue() == null) { // Some fields may be specified without a boost, so default the boost to 1.0 since a null value // will not be accepted by SimpleQueryParser. queryField.setValue(1.0F); } } } // Setup the operations that are enabled for the query. int enabledOps = 0; String opParam = defaultParams.get(SimpleParams.QO); if (opParam == null) { // All operations will be enabled. enabledOps = -1; } else { // Parse the specified enabled operations to be used by the query. String[] operations = opParam.split(","); for (String operation : operations) { Integer enabledOp = OPERATORS.get(operation.trim().toUpperCase(Locale.ROOT)); if (enabledOp != null) { enabledOps |= enabledOp; } } } // Create a SimpleQueryParser using the analyzer from the schema. final IndexSchema schema = req.getSchema(); parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema); // Set the default operator to be either 'AND' or 'OR' for the query. QueryParser.Operator defaultOp = QueryParsing.parseOP(defaultParams.get(QueryParsing.OP)); if (defaultOp == QueryParser.Operator.AND) { parser.setDefaultOperator(BooleanClause.Occur.MUST); } }
Example #5
Source File: SolrPluginUtils.java From lucene-solr with Apache License 2.0 | 4 votes |
public DisjunctionMaxQueryParser(QParser qp, String defaultField) { super(qp,defaultField); // don't trust that our parent class won't ever change its default setDefaultOperator(QueryParser.Operator.OR); }
Example #6
Source File: QueryParsing.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Parses default operator string into Operator object * @param operator the string from request * @return Operator.AND if string equals "AND", else return Operator.OR (default) */ public static QueryParser.Operator parseOP(String operator) { return "and".equalsIgnoreCase(operator) ? QueryParser.Operator.AND : QueryParser.Operator.OR; }