• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ScoreMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.search.join.ScoreMode的典型用法代码示例。如果您正苦于以下问题:Java ScoreMode类的具体用法?Java ScoreMode怎么用?Java ScoreMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ScoreMode类属于org.apache.lucene.search.join包,在下文中一共展示了ScoreMode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: minMaxQuery

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
private SearchResponse minMaxQuery(ScoreMode scoreMode, int minChildren, Integer maxChildren) throws SearchPhaseExecutionException {
    HasChildQueryBuilder hasChildQuery = hasChildQuery(
            "child",
            QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two")),
                    new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))
                    }).boostMode(CombineFunction.REPLACE).scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM), scoreMode)
            .minMaxChildren(minChildren, maxChildren != null ? maxChildren : HasChildQueryBuilder.DEFAULT_MAX_CHILDREN);

    return client()
            .prepareSearch("test")
            .setQuery(hasChildQuery)
            .addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ChildQuerySearchIT.java


示例2: testUnsupportedQueries

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testUnsupportedQueries() {
    RangeQueryBuilder rangeQuery1 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("2017-01-01||/D");
    RangeQueryBuilder rangeQuery2 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("now");
    PercolatorFieldMapper.verifyQuery(rangeQuery1);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(rangeQuery2));
    PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery1));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder((rangeQuery1)));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery1, new MatchAllQueryBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery2, new MatchAllQueryBuilder())));
    PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery1, new RandomScoreFunctionBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery2, new RandomScoreFunctionBuilder())));

    HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("_type", new MatchAllQueryBuilder(), ScoreMode.None);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasChildQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));

    HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("_type", new MatchAllQueryBuilder(), false);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasParentQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasParentQuery)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:PercolatorFieldMapperTests.java


示例3: assertAvgScoreMode

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
@Override
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DoubleNestedSortingTests.java


示例4: assertAvgScoreMode

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher, IndexFieldData.XFieldComparatorSource innerFieldComparator) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:FloatNestedSortingTests.java


示例5: assertAvgScoreMode

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractNumberNestedSortingTestCase.java


示例6: classSearch

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
@Override
public Scores classSearch(ModifiableSearchParams searchParams, ModifiableRankParams rankParams) {

    searchParams.model(BuiltInModel.FACT);

    if (rankParams instanceof ModifiableIndraParams) {
        configureDistributionalParams(searchParams.getKbId(), (ModifiableIndraParams) rankParams);
    }

    QueryBuilder queryBuilder = boolQuery()
            .must(nestedQuery("p",
                    termQuery("p.id", "is-a"),  ScoreMode.Max))
            .should(nestedQuery("o",
                    matchQuery("o.value", searchParams.getSearchTerm()),  ScoreMode.Max))
            .minimumShouldMatch("1");

    Searcher searcher = core.getSearcher(searchParams.getKbId());
    Scores scores = searcher.search(new ElasticQueryHolder(queryBuilder, searchParams));

    List<Score> classes2Score = scores.stream()
            .map(s -> new Score(((Fact)s.getEntry()).getObject(), s.getValue())).collect(Collectors.toList());

    return Rankers.apply(new Scores(classes2Score), rankParams, searchParams.getSearchTerm());
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:25,代码来源:ElasticEntitySearcher.java


示例7: propertySearch

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
@Override
public Scores propertySearch(ModifiableSearchParams searchParams, ModifiableRankParams rankParams) {

    searchParams.model(BuiltInModel.PROPERTY);

    if (rankParams instanceof ModifiableIndraParams) {
        configureDistributionalParams(searchParams.getKbId(), (ModifiableIndraParams) rankParams);
    }

    QueryBuilder queryBuilder = boolQuery()
            .should(nestedQuery("hyponyms",
                    matchQuery("hyponyms.word", searchParams.getSearchTerm()), ScoreMode.Max))
            .should(nestedQuery("hypernyms",
                    matchQuery("hypernyms.word", searchParams.getSearchTerm()), ScoreMode.Max))
            .should(nestedQuery("synonyms",
                    matchQuery("synonyms.word", searchParams.getSearchTerm()), ScoreMode.Max))
            .minimumNumberShouldMatch(1);

    Searcher searcher = core.getSearcher(searchParams.getKbId());
    Scores scores = searcher.search(new ElasticQueryHolder(queryBuilder, searchParams));

    return Rankers.apply(scores, rankParams, searchParams.getSearchTerm());
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:24,代码来源:ElasticEntitySearcher.java


示例8: testNestedInnerHitWrappedInParentChildInnerhit

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testNestedInnerHitWrappedInParentChildInnerhit() throws Exception {
    assertAcked(prepareCreate("test").addMapping("child_type", "_parent", "type=parent_type", "nested_type", "type=nested"));
    client().prepareIndex("test", "parent_type", "1").setSource("key", "value").get();
    client().prepareIndex("test", "child_type", "2").setParent("1").setSource("nested_type", Collections.singletonMap("key", "value"))
        .get();
    refresh();
    SearchResponse response = client().prepareSearch("test")
        .setQuery(boolQuery().must(matchQuery("key", "value"))
            .should(hasChildQuery("child_type", nestedQuery("nested_type", matchAllQuery(), ScoreMode.None)
                .innerHit(new InnerHitBuilder(), false), ScoreMode.None).innerHit(new InnerHitBuilder(), false)))
        .get();
    assertHitCount(response, 1);
    SearchHit hit = response.getHits().getAt(0);
    assertThat(hit.getInnerHits().get("child_type").getAt(0).field("_parent").getValue(), equalTo("1"));
    assertThat(hit.getInnerHits().get("child_type").getAt(0).getInnerHits().get("nested_type").getAt(0).field("_parent"), nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:InnerHitsIT.java


示例9: test2744

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void test2744() throws IOException {
    assertAcked(prepareCreate("test")
            .addMapping("foo")
            .addMapping("test", "_parent", "type=foo"));
    ensureGreen();

    // index simple data
    client().prepareIndex("test", "foo", "1").setSource("foo", 1).get();
    client().prepareIndex("test", "test").setSource("foo", 1).setParent("1").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch("test").
            setQuery(hasChildQuery("test", matchQuery("foo", 1), ScoreMode.None))
            .get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ChildQuerySearchIT.java


示例10: testDfsSearchType

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testDfsSearchType() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("parent")
            .addMapping("child", "_parent", "type=parent"));
    ensureGreen();

    // index simple data
    client().prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1").get();
    client().prepareIndex("test", "child", "c1").setSource("c_field", "red").setParent("p1").get();
    client().prepareIndex("test", "child", "c2").setSource("c_field", "yellow").setParent("p1").get();
    client().prepareIndex("test", "parent", "p2").setSource("p_field", "p_value2").get();
    client().prepareIndex("test", "child", "c3").setSource("c_field", "blue").setParent("p2").get();
    client().prepareIndex("test", "child", "c4").setSource("c_field", "red").setParent("p2").get();

    refresh();

    SearchResponse searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(boolQuery().mustNot(hasChildQuery("child", boolQuery().should(queryStringQuery("c_field:*")), ScoreMode.None)))
            .get();
    assertNoFailures(searchResponse);

    searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(boolQuery().mustNot(hasParentQuery("parent", boolQuery().should(queryStringQuery("p_field:*")), false))).execute()
            .actionGet();
    assertNoFailures(searchResponse);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ChildQuerySearchIT.java


示例11: testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrChildDocs

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrChildDocs() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("parent")
            .addMapping("child", "_parent", "type=parent"));
    ensureGreen();

    client().prepareIndex("test", "parent", "1").setSource("p_field", 1).get();
    client().prepareIndex("test", "child", "1").setParent("1").setSource("c_field", 1).get();
    client().admin().indices().prepareFlush("test").get();

    client().prepareIndex("test", "type1", "1").setSource("p_field", 1).get();
    client().admin().indices().prepareFlush("test").get();

    SearchResponse searchResponse = client().prepareSearch("test")
            .setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", matchAllQuery(), ScoreMode.None))).get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));

    searchResponse = client().prepareSearch("test")
            .setQuery(boolQuery().must(matchAllQuery()).filter(hasParentQuery("parent", matchAllQuery(), false))).get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:ChildQuerySearchIT.java


示例12: testHasChildAndHasParentFilter_withFilter

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testHasChildAndHasParentFilter_withFilter() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("parent")
            .addMapping("child", "_parent", "type=parent"));
    ensureGreen();

    client().prepareIndex("test", "parent", "1").setSource("p_field", 1).get();
    client().prepareIndex("test", "child", "2").setParent("1").setSource("c_field", 1).get();
    client().admin().indices().prepareFlush("test").get();

    client().prepareIndex("test", "type1", "3").setSource("p_field", 2).get();
    client().admin().indices().prepareFlush("test").get();

    SearchResponse searchResponse = client().prepareSearch("test")
            .setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", termQuery("c_field", 1), ScoreMode.None)))
            .get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));

    searchResponse = client().prepareSearch("test")
            .setQuery(boolQuery().must(matchAllQuery()).filter(hasParentQuery("parent", termQuery("p_field", 1), false))).get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("2"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ChildQuerySearchIT.java


示例13: testHasChildInnerHitsHighlighting

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testHasChildInnerHitsHighlighting() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("parent")
            .addMapping("child", "_parent", "type=parent"));
    ensureGreen();

    client().prepareIndex("test", "parent", "1").setSource("p_field", 1).get();
    client().prepareIndex("test", "child", "2").setParent("1").setSource("c_field", "foo bar").get();
    client().admin().indices().prepareFlush("test").get();

    SearchResponse searchResponse = client().prepareSearch("test").setQuery(
            hasChildQuery("child", matchQuery("c_field", "foo"), ScoreMode.None)
                .innerHit(new InnerHitBuilder().setHighlightBuilder(
                    new HighlightBuilder().field(new Field("c_field")
                            .highlightQuery(QueryBuilders.matchQuery("c_field", "bar")))), false))
            .get();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));
    SearchHit[] searchHits = searchResponse.getHits().getHits()[0].getInnerHits().get("child").getHits();
    assertThat(searchHits.length, equalTo(1));
    assertThat(searchHits[0].getHighlightFields().get("c_field").getFragments().length, equalTo(1));
    assertThat(searchHits[0].getHighlightFields().get("c_field").getFragments()[0].string(), equalTo("foo <em>bar</em>"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ChildQuerySearchIT.java


示例14: testQueryBeforeChildType

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testQueryBeforeChildType() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("features")
            .addMapping("posts", "_parent", "type=features")
            .addMapping("specials"));
    ensureGreen();

    client().prepareIndex("test", "features", "1").setSource("field", "foo").get();
    client().prepareIndex("test", "posts", "1").setParent("1").setSource("field", "bar").get();
    refresh();

    SearchResponse resp;
    resp = client().prepareSearch("test")
            .setSource(new SearchSourceBuilder().query(QueryBuilders.hasChildQuery("posts", QueryBuilders.matchQuery("field", "bar"), ScoreMode.None)))
            .get();
    assertHitCount(resp, 1L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ChildQuerySearchIT.java


示例15: doCreateTestQueryBuilder

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected HasChildQueryBuilder doCreateTestQueryBuilder() {
    int min = randomIntBetween(0, Integer.MAX_VALUE / 2);
    int max = randomIntBetween(min, Integer.MAX_VALUE);

    QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }

    HasChildQueryBuilder hqb = new HasChildQueryBuilder(CHILD_TYPE, innerQueryBuilder,
            RandomPicks.randomFrom(random(), ScoreMode.values()));
    hqb.minMaxChildren(min, max);
    hqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        hqb.innerHit(new InnerHitBuilder()
                .setName(randomAsciiOfLengthBetween(1, 10))
                .setSize(randomIntBetween(0, 100))
                .addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)), hqb.ignoreUnmapped());
    }
    return hqb;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:HasChildQueryBuilderTests.java


示例16: testIllegalValues

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testIllegalValues() {
    QueryBuilder query = RandomQueryBuilder.createQuery(random());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> QueryBuilders.hasChildQuery(null, query, ScoreMode.None));
    assertEquals("[has_child] requires 'type' field", e.getMessage());

    e = expectThrows(IllegalArgumentException.class, () -> QueryBuilders.hasChildQuery("foo", null, ScoreMode.None));
    assertEquals("[has_child] requires 'query' field", e.getMessage());

    e = expectThrows(IllegalArgumentException.class, () -> QueryBuilders.hasChildQuery("foo", query, null));
    assertEquals("[has_child] requires 'score_mode' field", e.getMessage());

    int positiveValue = randomIntBetween(0, Integer.MAX_VALUE);
    HasChildQueryBuilder foo = QueryBuilders.hasChildQuery("foo", query, ScoreMode.None); // all good
    e = expectThrows(IllegalArgumentException.class, () -> foo.minMaxChildren(randomIntBetween(Integer.MIN_VALUE, -1), positiveValue));
    assertEquals("[has_child] requires non-negative 'min_children' field", e.getMessage());

    e = expectThrows(IllegalArgumentException.class, () -> foo.minMaxChildren(positiveValue, randomIntBetween(Integer.MIN_VALUE, -1)));
    assertEquals("[has_child] requires non-negative 'max_children' field", e.getMessage());

    e = expectThrows(IllegalArgumentException.class, () -> foo.minMaxChildren(positiveValue, positiveValue - 10));
    assertEquals("[has_child] 'max_children' is less than 'min_children'", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:HasChildQueryBuilderTests.java


示例17: addSubQuery

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
/**
 * 增加嵌套插
 * 
 * @param boolQuery
 * @param where
 * @param subQuery
 */
private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder subQuery) {
       if(where instanceof Condition){
           Condition condition = (Condition) where;

           if(condition.isNested()){
               subQuery = QueryBuilders.nestedQuery(condition.getNestedPath(), subQuery, ScoreMode.None);
           } else if(condition.isChildren()) {
           	subQuery = QueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);
           }
       }

	if (where.getConn() == CONN.AND) {
		boolQuery.must(subQuery);
	} else {
		boolQuery.should(subQuery);
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:25,代码来源:QueryMaker.java


示例18: doCreateTestQueryBuilder

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected NestedQueryBuilder doCreateTestQueryBuilder() {
    QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }
    NestedQueryBuilder nqb = new NestedQueryBuilder("nested1", innerQueryBuilder,
            RandomPicks.randomFrom(random(), ScoreMode.values()));
    nqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        nqb.innerHit(new InnerHitBuilder()
                .setName(randomAsciiOfLengthBetween(1, 10))
                .setSize(randomIntBetween(0, 100))
                .addSort(new FieldSortBuilder(INT_FIELD_NAME).order(SortOrder.ASC)), nqb.ignoreUnmapped());
    }
    return nqb;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:NestedQueryBuilderTests.java


示例19: testInlineLeafInnerHitsNestedQueryViaDisMaxQuery

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testInlineLeafInnerHitsNestedQueryViaDisMaxQuery() {
    InnerHitBuilder leafInnerHits1 = randomInnerHits();
    NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None)
            .innerHit(leafInnerHits1, false);

    InnerHitBuilder leafInnerHits2 = randomInnerHits();
    HasChildQueryBuilder hasChildQueryBuilder = new HasChildQueryBuilder("type", new MatchAllQueryBuilder(), ScoreMode.None)
            .innerHit(leafInnerHits2, false);

    DisMaxQueryBuilder disMaxQueryBuilder = new DisMaxQueryBuilder();
    disMaxQueryBuilder.add(nestedQueryBuilder);
    disMaxQueryBuilder.add(hasChildQueryBuilder);
    Map<String, InnerHitBuilder> innerHitBuilders = new HashMap<>();
    disMaxQueryBuilder.extractInnerHitBuilders(innerHitBuilders);
    assertThat(innerHitBuilders.size(), equalTo(2));
    assertThat(innerHitBuilders.get(leafInnerHits1.getName()), notNullValue());
    assertThat(innerHitBuilders.get(leafInnerHits2.getName()), notNullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:InnerHitBuilderTests.java


示例20: testBuild_ingoreUnmappedNestQuery

import org.apache.lucene.search.join.ScoreMode; //导入依赖的package包/类
public void testBuild_ingoreUnmappedNestQuery() throws Exception {
    QueryShardContext queryShardContext = mock(QueryShardContext.class);
    when(queryShardContext.getObjectMapper("path")).thenReturn(null);
    SearchContext searchContext = mock(SearchContext.class);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);

    InnerHitBuilder leafInnerHits = randomInnerHits();
    NestedQueryBuilder query1 = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None);
    query1.innerHit(leafInnerHits, false);
    expectThrows(IllegalStateException.class, () -> query1.innerHit().build(searchContext, new InnerHitsContext()));

    NestedQueryBuilder query2 = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None);
    query2.innerHit(leafInnerHits, true);
    InnerHitsContext innerHitsContext = new InnerHitsContext();
    query2.innerHit().build(searchContext, innerHitsContext);
    assertThat(innerHitsContext.getInnerHits().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:InnerHitBuilderTests.java



注:本文中的org.apache.lucene.search.join.ScoreMode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FontConfiguration类代码示例发布时间:2022-05-21
下一篇:
Java DefaultFontMapper类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap