Search in sources :

Example 6 with FilterFunctionBuilder

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);
    }
}
Also used : WebConfigToLabelCQ(org.codelibs.fess.es.config.cbean.cq.WebConfigToLabelCQ) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) ArrayList(java.util.ArrayList)

Example 7 with FilterFunctionBuilder

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);
    }
}
Also used : FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) WebConfigToRoleCQ(org.codelibs.fess.es.config.cbean.cq.WebConfigToRoleCQ) ArrayList(java.util.ArrayList)

Example 8 with FilterFunctionBuilder

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);
}
Also used : FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder)

Example 9 with FilterFunctionBuilder

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]));
    }
}
Also used : FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) ArrayList(java.util.ArrayList) GeoPoint(org.elasticsearch.common.geo.GeoPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Version(org.elasticsearch.Version) SearchHits(org.elasticsearch.search.SearchHits) ElasticsearchAssertions.assertOrderedSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 10 with FilterFunctionBuilder

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));
}
Also used : FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) RandomQueryBuilder(org.elasticsearch.index.query.RandomQueryBuilder) WrapperQueryBuilder(org.elasticsearch.index.query.WrapperQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) AbstractQueryBuilder(org.elasticsearch.index.query.AbstractQueryBuilder)

Aggregations

FilterFunctionBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder)15 ArrayList (java.util.ArrayList)10 FunctionScoreQueryBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 GeoPoint (org.elasticsearch.common.geo.GeoPoint)3 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)3 SearchHits (org.elasticsearch.search.SearchHits)3 ElasticsearchAssertions.assertOrderedSearchHits (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits)3 ElasticsearchAssertions.assertSearchHits (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits)3 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 Script (org.elasticsearch.script.Script)2 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)2 DataConfigToLabelCQ (org.codelibs.fess.es.config.cbean.cq.DataConfigToLabelCQ)1 DataConfigToRoleCQ (org.codelibs.fess.es.config.cbean.cq.DataConfigToRoleCQ)1 FileConfigToLabelCQ (org.codelibs.fess.es.config.cbean.cq.FileConfigToLabelCQ)1 FileConfigToRoleCQ (org.codelibs.fess.es.config.cbean.cq.FileConfigToRoleCQ)1 LabelToRoleCQ (org.codelibs.fess.es.config.cbean.cq.LabelToRoleCQ)1 WebConfigToLabelCQ (org.codelibs.fess.es.config.cbean.cq.WebConfigToLabelCQ)1 WebConfigToRoleCQ (org.codelibs.fess.es.config.cbean.cq.WebConfigToRoleCQ)1 SearchFieldLogCQ (org.codelibs.fess.es.log.cbean.cq.SearchFieldLogCQ)1