use of org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder in project fess by codelibs.
the class BsWebConfigToLabelCQ method functionScore.
// ===================================================================================
// Query Control
// =============
public void functionScore(OperatorCall<WebConfigToLabelCQ> queryLambda, ScoreFunctionCall<ScoreFunctionCreator<WebConfigToLabelCQ>> functionsLambda, final ConditionOptionCall<FunctionScoreQueryBuilder> opLambda) {
WebConfigToLabelCQ cq = new WebConfigToLabelCQ();
queryLambda.callback(cq);
final Collection<FilterFunctionBuilder> list = new ArrayList<>();
if (functionsLambda != null) {
functionsLambda.callback((cqLambda, scoreFunctionBuilder) -> {
WebConfigToLabelCQ cf = new WebConfigToLabelCQ();
cqLambda.callback(cf);
list.add(new FilterFunctionBuilder(cf.getQuery(), scoreFunctionBuilder));
});
}
final FunctionScoreQueryBuilder builder = regFunctionScoreQ(cq.getQuery(), list);
if (opLambda != null) {
opLambda.callback(builder);
}
}
use of org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder in project fess by codelibs.
the class BsWebConfigToRoleCQ method functionScore.
// ===================================================================================
// Query Control
// =============
public void functionScore(OperatorCall<WebConfigToRoleCQ> queryLambda, ScoreFunctionCall<ScoreFunctionCreator<WebConfigToRoleCQ>> functionsLambda, final ConditionOptionCall<FunctionScoreQueryBuilder> opLambda) {
WebConfigToRoleCQ cq = new WebConfigToRoleCQ();
queryLambda.callback(cq);
final Collection<FilterFunctionBuilder> list = new ArrayList<>();
if (functionsLambda != null) {
functionsLambda.callback((cqLambda, scoreFunctionBuilder) -> {
WebConfigToRoleCQ cf = new WebConfigToRoleCQ();
cqLambda.callback(cf);
list.add(new FilterFunctionBuilder(cf.getQuery(), scoreFunctionBuilder));
});
}
final FunctionScoreQueryBuilder builder = regFunctionScoreQ(cq.getQuery(), list);
if (opLambda != null) {
opLambda.callback(builder);
}
}
use of org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder in project elasticsearch by elastic.
the class QueryDSLDocumentationTests method testFunctionScore.
public void testFunctionScore() {
FilterFunctionBuilder[] functions = { new FunctionScoreQueryBuilder.FilterFunctionBuilder(matchQuery("name", "kimchy"), randomFunction("ABCDEF")), new FunctionScoreQueryBuilder.FilterFunctionBuilder(exponentialDecayFunction("age", 0L, 1L)) };
functionScoreQuery(functions);
}
use of org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder in project elasticsearch by elastic.
the class DecayFunctionScoreIT method testManyDocsLin.
public void testManyDocsLin() throws Exception {
Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.CURRENT);
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
XContentBuilder xContentBuilder = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text").endObject().startObject("date").field("type", "date").field("doc_values", true).endObject().startObject("num").field("type", "double").field("doc_values", true).endObject().startObject("geo").field("type", "geo_point").field("ignore_malformed", true);
xContentBuilder.endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", xContentBuilder));
int numDocs = 200;
List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
for (int i = 0; i < numDocs; i++) {
double lat = 100 + (int) (10.0 * (i) / (numDocs));
double lon = 100;
int day = (int) (29.0 * (i) / (numDocs)) + 1;
String dayString = day < 10 ? "0" + Integer.toString(day) : Integer.toString(day);
String date = "2013-05-" + dayString;
indexBuilders.add(client().prepareIndex().setType("type").setId(Integer.toString(i)).setIndex("test").setSource(jsonBuilder().startObject().field("test", "value").field("date", date).field("num", i).startObject("geo").field("lat", lat).field("lon", lon).endObject().endObject()));
}
indexRandom(true, indexBuilders);
List<Float> lonlat = new ArrayList<>();
lonlat.add(100f);
lonlat.add(110f);
ActionFuture<SearchResponse> response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(searchSource().size(numDocs).query(functionScoreQuery(termQuery("test", "value"), new FilterFunctionBuilder[] { new FilterFunctionBuilder(linearDecayFunction("date", "2013-05-30", "+15d")), new FilterFunctionBuilder(linearDecayFunction("geo", lonlat, "1000km")), new FilterFunctionBuilder(linearDecayFunction("num", numDocs, numDocs / 2.0)) }).scoreMode(ScoreMode.MULTIPLY).boostMode(CombineFunction.REPLACE))));
SearchResponse sr = response.actionGet();
assertNoFailures(sr);
SearchHits sh = sr.getHits();
assertThat(sh.getHits().length, equalTo(numDocs));
double[] scores = new double[numDocs];
for (int i = 0; i < numDocs; i++) {
scores[Integer.parseInt(sh.getAt(i).getId())] = sh.getAt(i).getScore();
}
for (int i = 0; i < numDocs - 1; i++) {
assertThat(scores[i], lessThan(scores[i + 1]));
}
}
use of org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder in project elasticsearch by elastic.
the class FunctionScoreQueryBuilderTests method testIllegalArguments.
public void testIllegalArguments() {
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder((QueryBuilder) null));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder((ScoreFunctionBuilder<?>) null));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder((FilterFunctionBuilder[]) null));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder(null, randomFunction(123)));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder(matchAllQuery(), (ScoreFunctionBuilder<?>) null));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder(matchAllQuery(), (FilterFunctionBuilder[]) null));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder(null, new FilterFunctionBuilder[0]));
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder(matchAllQuery(), new FilterFunctionBuilder[] { null }));
expectThrows(IllegalArgumentException.class, () -> new FilterFunctionBuilder((ScoreFunctionBuilder<?>) null));
expectThrows(IllegalArgumentException.class, () -> new FilterFunctionBuilder(null, randomFunction(123)));
expectThrows(IllegalArgumentException.class, () -> new FilterFunctionBuilder(matchAllQuery(), null));
FunctionScoreQueryBuilder builder = new FunctionScoreQueryBuilder(matchAllQuery());
expectThrows(IllegalArgumentException.class, () -> builder.scoreMode(null));
expectThrows(IllegalArgumentException.class, () -> builder.boostMode(null));
}
Aggregations