public Query parse() throws ParseException { String qstr = getString(); if (qstr == null) return null; String defaultField = getParam(CommonParams.DF); if (defaultField == null) { defaultField = getReq().getSchema().getDefaultSearchFieldName(); } lparser = new SolrQueryParser(this, defaultField); lparser.setDefaultOperator( QueryParsing.getQueryParserDefaultOperator( getReq().getSchema(), getParam(QueryParsing.OP))); return lparser.parse(qstr); }
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 = QueryParsing.getDefaultField(req.getSchema(), 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 + ", " + CommonParams.DF + ", nor the default search field 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.getQueryParserDefaultOperator( req.getSchema(), defaultParams.get(QueryParsing.OP)); if (defaultOp == QueryParser.Operator.AND) { parser.setDefaultOperator(BooleanClause.Occur.MUST); } }