/** * {@inheritDoc} * * @see org.apache.solr.search.QParser#parse() */ @Override public Query parse() throws ParseException { SolrQueryParser solrParser = new SolrQueryParser(this, DEFAULT_FIELD); solrParser.setAllowLeadingWildcard(true); return solrParser.parse(super.qstr); }
/** * Helper utility for parsing a query using the Lucene QueryParser syntax. * @param qs query expression in standard Lucene syntax * @param defaultField default field used for unqualified search terms in the query expression * @param schema used for default operator (overridden by params) and passed to the query parser for field format analysis information */ public static Query parseQuery(String qs, String defaultField, IndexSchema schema) { try { Query query = schema.getSolrQueryParser(defaultField).parse(qs); if (SolrCore.log.isTraceEnabled() ) { SolrCore.log.trace("After QueryParser:" + query); } return query; } catch (ParseException e) { SolrCore.log(e); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Error parsing Lucene query",e); } }
@Override public Query parse() throws ParseException { String defaultField = getParam(CommonParams.DF); if (defaultField == null) { // TODO poussin 20101216 normalement on devrait retrouver cette // valeur dans la config. Mais en fait a chaque fois on passe // ici car defaultField est null :( alors que dans schema.xml // on a bien defini le defaultField :( defaultField = WikittySolrConstant.SOLR_DEFAULT_FIELD; } lparser = new SolrQueryParser(this, defaultField); lparser.setAllowLeadingWildcard(true); String opParam = getParam(QueryParsing.OP); if (opParam != null) { lparser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR); } String qstr = getString(); if (log.isDebugEnabled()) { log.debug("Query parse : " + qstr); } return lparser.parse(qstr); }
/** * Helper utility for parsing a query using the Lucene QueryParser syntax. * @param qs query expression in standard Lucene syntax * @param defaultField default field used for unqualified search terms in the query expression * @param params used to determine the default operator, overriding the schema specified operator * @param schema used for default operator (overridden by params) and passed to the query parser for field format analysis information */ public static Query parseQuery(String qs, String defaultField, SolrParams params, IndexSchema schema) { try { SolrQueryParser parser = schema.getSolrQueryParser(defaultField); String opParam = params.get(OP); if (opParam != null) { parser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR); } Query query = parser.parse(qs); if (SolrCore.log.isTraceEnabled() ) { SolrCore.log.trace("After QueryParser:" + query); } return query; } catch (ParseException e) { SolrCore.log(e); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Query parsing error: " + e.getMessage(),e); } }
public Query parse() throws ParseException { String qstr = getString(); String defaultField = getParam(CommonParams.DF); if (defaultField==null) { defaultField = getReq().getSchema().getDefaultSearchFieldName(); } lparser = new SolrQueryParser(this, defaultField); // these could either be checked & set here, or in the SolrQueryParser constructor String opParam = getParam(QueryParsing.OP); if (opParam != null) { lparser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR); } else { // try to get default operator from schema QueryParser.Operator operator = getReq().getSchema().getSolrQueryParser(null).getDefaultOperator(); lparser.setDefaultOperator(null == operator ? QueryParser.Operator.OR : operator); } return lparser.parse(qstr); }