Java Code Examples for org.apache.lucene.search.BooleanQuery#setBoost()
The following examples show how to use
org.apache.lucene.search.BooleanQuery#setBoost() .
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: QueryStringQueryConstructor.java From linden with Apache License 2.0 | 5 votes |
@Override protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException { LindenQueryStringQuery stringQuery = lindenQuery.getQueryString(); QueryParser.Operator op = QueryParser.Operator.OR; if (stringQuery.isSetOperator() && stringQuery.getOperator() == Operator.AND) { op = QueryParser.Operator.AND; } QueryParser queryParser = new LindenQueryParser(config); String content = stringQuery.getQuery(); try { queryParser.setDefaultOperator(op); Query query = queryParser.parse(content); // disable coord if (query instanceof BooleanQuery) { BooleanQuery bQuery = (BooleanQuery) query; BooleanQuery booleanQuery = new BooleanQuery(stringQuery.isDisableCoord()); BooleanClause[] clauses = bQuery.getClauses(); for (BooleanClause clause : clauses) { booleanQuery.add(clause); } booleanQuery.setBoost(query.getBoost()); query = booleanQuery; } return query; } catch (ParseException e) { throw new IOException(Throwables.getStackTraceAsString(e)); } }
Example 2
Source File: BooleanQueryWritable.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public void readFields(DataInput in) throws IOException { query = new BooleanQuery(in.readBoolean()); query.setBoost(in.readFloat()); query.setMinimumNumberShouldMatch(in.readInt()); int length = in.readInt(); for (int i = 0; i < length; i++) { BooleanClauseWritable booleanClauseWritable = new BooleanClauseWritable(); booleanClauseWritable.readFields(in); query.add(booleanClauseWritable.getBooleanClause()); } }
Example 3
Source File: FilteredQueryParser.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { deprecationLogger.deprecated("The [filtered] query is deprecated, please use a [bool] query instead with a [must] " + "clause for the query part and a [filter] clause for the filter part."); XContentParser parser = parseContext.parser(); Query query = Queries.newMatchAllQuery(); Query filter = null; boolean filterFound = false; float boost = 1.0f; String queryName = null; String currentFieldName = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (parseContext.isDeprecatedSetting(currentFieldName)) { // skip } else if (token == XContentParser.Token.START_OBJECT) { if ("query".equals(currentFieldName)) { query = parseContext.parseInnerQuery(); } else if ("filter".equals(currentFieldName)) { filterFound = true; filter = parseContext.parseInnerFilter(); } else { throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("strategy".equals(currentFieldName)) { // ignore } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else { throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]"); } } } // parsed internally, but returned null during parsing... if (query == null) { return null; } BooleanQuery filteredQuery = Queries.filtered(query, filter); filteredQuery.setBoost(boost); if (queryName != null) { parseContext.addNamedQuery(queryName, filteredQuery); } return filteredQuery; }