/** * Returns a version of the given query that always matches with the * given score. * @param query the query * @param score the desired score * @return the constant score query */ public static ConstantScoreQuery constantScore( final Query query, final float score) { ConstantScoreQuery result = new ConstantScoreQuery(query); result.setBoost(score); return result; }
@Override protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException { Filter filter = null; try { JSONObject newJson = new FastJSONObject(); newJson.put(QUERY_TYPE, jsonQuery); filter = FilterConstructor.constructFilter(newJson, null/* * QueryParser is not used by this * filter */); } catch (Exception e) { throw new JSONException(e); } ConstantScoreQuery query = new ConstantScoreQuery(filter); query.setBoost((float) jsonQuery.getJSONObject((String) jsonQuery.keys().next()).optDouble( BOOST_PARAM, 1.0)); return query; } }
@Override protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException { Filter filter = null; try { JSONObject newJson = new FastJSONObject(); newJson.put(QUERY_TYPE, jsonQuery); filter = FilterConstructor.constructFilter(newJson, null/* * QueryParser is not used by this * filter */); } catch (Exception e) { throw new JSONException(e); } ConstantScoreQuery query = new ConstantScoreQuery(filter); Object obj = jsonQuery.get((String) jsonQuery.keys().next()); if (obj instanceof JSONObject) { query.setBoost((float) ((JSONObject) obj).optDouble(BOOST_PARAM, 1.0)); } return query; } }
@Override protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException { JSONObject filterJson = new FastJSONObject(); filterJson.put(QUERY_TYPE, jsonQuery); Filter filter = null; try { filter = FilterConstructor.constructFilter(filterJson, null/* * QueryParser is not used by this * filter */); } catch (Exception e) { throw new JSONException(e); } ConstantScoreQuery query = new ConstantScoreQuery(filter); query.setBoost((float) jsonQuery.optDouble(BOOST_PARAM, 1.0)); return query; } }