当前位置: 首页>>代码示例>>Java>>正文


Java HighlightBuilder类代码示例

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


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

示例1: TopHitsAggregatorFactory

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public TopHitsAggregatorFactory(String name, int from, int size, boolean explain, boolean version, boolean trackScores,
        Optional<SortAndFormats> sort, HighlightBuilder highlightBuilder, StoredFieldsContext storedFieldsContext,
        List<String> docValueFields, List<ScriptFieldsContext.ScriptField> scriptFields, FetchSourceContext fetchSourceContext,
        SearchContext context, AggregatorFactory<?> parent, AggregatorFactories.Builder subFactories, Map<String, Object> metaData)
        throws IOException {
    super(name, context, parent, subFactories, metaData);
    this.from = from;
    this.size = size;
    this.explain = explain;
    this.version = version;
    this.trackScores = trackScores;
    this.sort = sort;
    this.highlightBuilder = highlightBuilder;
    this.storedFieldsContext = storedFieldsContext;
    this.docValueFields = docValueFields;
    this.scriptFields = scriptFields;
    this.fetchSourceContext = fetchSourceContext;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TopHitsAggregatorFactory.java

示例2: testThatCustomHighlighterReceivesFieldsInOrder

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testThatCustomHighlighterReceivesFieldsInOrder() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("test").setTypes("test")
            .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).should(QueryBuilders
                    .termQuery("name", "arbitrary")))
            .highlighter(
                    new HighlightBuilder().highlighterType("test-custom").field("name").field("other_name").field("other_other_name")
                            .useExplicitFieldOrder(true))
            .get();

    assertHighlight(searchResponse, 0, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 0, "other_name", 0, equalTo("standard response for other_name at position 2"));
    assertHighlight(searchResponse, 0, "other_other_name", 0, equalTo("standard response for other_other_name at position 3"));
    assertHighlight(searchResponse, 1, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 1, "other_name", 0, equalTo("standard response for other_name at position 2"));
    assertHighlight(searchResponse, 1, "other_other_name", 0, equalTo("standard response for other_other_name at position 3"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CustomHighlighterSearchIT.java

示例3: testHasChildInnerHitsHighlighting

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的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

示例4: selectMatchAll

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public String selectMatchAll(String indexs,String types,String field,String value){
	try {
		if(client==null){
			init();
		}
		SearchRequestBuilder request = client.prepareSearch(indexs.split(",")).setTypes(types.split(","));
		request.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.setQuery(QueryBuilders.matchQuery(field, value));
		request.highlighter(new HighlightBuilder().field(field));
		request.addAggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		request.setExplain(false);
		SearchResponse response = request.get();
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:20,代码来源:ElasticsearchTransportFactory.java

示例5: selectTermAll

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public String selectTermAll(String indexs,String types,String field,String value){
	try {
		if(client==null){
			init();
		}
		SearchRequestBuilder request = client.prepareSearch(indexs.split(",")).setTypes(types.split(","));
		request.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.setQuery(QueryBuilders.termQuery(field, value));
		request.highlighter(new HighlightBuilder().field(field));
		request.addAggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		request.setExplain(false);
		SearchResponse response = request.get();
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:20,代码来源:ElasticsearchExtendTransportFactory.java

示例6: updateRequestWithHighlight

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
protected void updateRequestWithHighlight(Select select, SearchRequestBuilder request) {
    boolean foundAnyHighlights = false;
    HighlightBuilder highlightBuilder = new HighlightBuilder();
    for(Hint hint : select.getHints()){
        if(hint.getType() == HintType.HIGHLIGHT){
            HighlightBuilder.Field highlightField = parseHighlightField(hint.getParams());
            if(highlightField != null){
                foundAnyHighlights = true;
                highlightBuilder.field(highlightField);
            }
        }
    }
    if(foundAnyHighlights){
        request.highlighter(highlightBuilder);
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:17,代码来源:QueryAction.java

示例7: testComplexQuery

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testComplexQuery() throws IOException {
    ClusteringActionResponse result = new ClusteringActionRequestBuilder(client)
        .setQueryHint("data mining")
        .addSourceFieldMapping("title", LogicalField.TITLE)
        .addHighlightedFieldMapping("content", LogicalField.CONTENT)
        .setSearchRequest(
          client.prepareSearch()
                .setIndices(INDEX_TEST)
                .setTypes("test")
                .setSize(100)
                .setQuery(QueryBuilders.termQuery("content", "data"))
                .highlighter(new HighlightBuilder().preTags("").postTags(""))
                .setFetchSource(new String[] {"title"}, null)
                .highlighter(new HighlightBuilder().field("content")))
        .execute().actionGet();

    checkValid(result);
    checkJsonSerialization(result);
}
 
开发者ID:carrot2,项目名称:elasticsearch-carrot2,代码行数:20,代码来源:ClusteringActionIT.java

示例8: highlighter

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
/**
 * Adds highlight to perform as part of the search.
 */
public TopHitsAggregationBuilder highlighter(HighlightBuilder highlightBuilder) {
    if (highlightBuilder == null) {
        throw new IllegalArgumentException("[highlightBuilder] must not be null: [" + name + "]");
    }
    this.highlightBuilder = highlightBuilder;
    return this;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:TopHitsAggregationBuilder.java

示例9: testThatCustomHighlightersAreSupported

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testThatCustomHighlightersAreSupported() throws IOException {
    SearchResponse searchResponse = client().prepareSearch("test").setTypes("test")
            .setQuery(QueryBuilders.matchAllQuery())
            .highlighter(new HighlightBuilder().field("name").highlighterType("test-custom"))
            .execute().actionGet();
    assertHighlight(searchResponse, 0, "name", 0, equalTo("standard response for name at position 1"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:CustomHighlighterSearchIT.java

示例10: testThatCustomHighlighterCanBeConfiguredPerField

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testThatCustomHighlighterCanBeConfiguredPerField() throws Exception {
    HighlightBuilder.Field highlightConfig = new HighlightBuilder.Field("name");
    highlightConfig.highlighterType("test-custom");
    Map<String, Object> options = new HashMap<>();
    options.put("myFieldOption", "someValue");
    highlightConfig.options(options);

    SearchResponse searchResponse = client().prepareSearch("test").setTypes("test")
            .setQuery(QueryBuilders.matchAllQuery())
            .highlighter(new HighlightBuilder().field(highlightConfig))
            .execute().actionGet();

    assertHighlight(searchResponse, 0, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 0, "name", 1, equalTo("field:myFieldOption:someValue"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:CustomHighlighterSearchIT.java

示例11: testThatCustomHighlighterCanBeConfiguredGlobally

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testThatCustomHighlighterCanBeConfiguredGlobally() throws Exception {
    Map<String, Object> options = new HashMap<>();
    options.put("myGlobalOption", "someValue");

    SearchResponse searchResponse = client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())
            .highlighter(new HighlightBuilder().field("name").highlighterType("test-custom").options(options))
            .execute().actionGet();

    assertHighlight(searchResponse, 0, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 0, "name", 1, equalTo("field:myGlobalOption:someValue"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:CustomHighlighterSearchIT.java

示例12: testHighlightersIgnoreParentChild

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
public void testHighlightersIgnoreParentChild() {
    assertAcked(prepareCreate("test")
            .addMapping("parent-type", "searchText", "type=text,term_vector=with_positions_offsets,index_options=offsets")
            .addMapping("child-type", "_parent", "type=parent-type", "searchText",
                    "type=text,term_vector=with_positions_offsets,index_options=offsets"));
    client().prepareIndex("test", "parent-type", "parent-id").setSource("searchText", "quick brown fox").get();
    client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("searchText", "quick brown fox").get();
    refresh();

    String[] highlightTypes = new String[] {"plain", "fvh", "postings"};
    for (String highlightType : highlightTypes) {
        logger.info("Testing with highlight type [{}]", highlightType);
        SearchResponse searchResponse = client().prepareSearch("test")
                .setQuery(new BoolQueryBuilder()
                        .must(new MatchQueryBuilder("searchText", "fox"))
                        .must(new HasChildQueryBuilder("child-type", new MatchAllQueryBuilder(), ScoreMode.None))
                )
                .highlighter(new HighlightBuilder().field(new HighlightBuilder.Field("searchText").highlighterType(highlightType)))
                .get();
        assertHitCount(searchResponse, 1);
        assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("parent-id"));
        HighlightField highlightField = searchResponse.getHits().getAt(0).getHighlightFields().get("searchText");
        assertThat(highlightField.getFragments()[0].string(), equalTo("quick brown <em>fox</em>"));

        searchResponse = client().prepareSearch("test")
                .setQuery(new BoolQueryBuilder()
                        .must(new MatchQueryBuilder("searchText", "fox"))
                        .must(new HasParentQueryBuilder("parent-type", new MatchAllQueryBuilder(), false))
                )
                .highlighter(new HighlightBuilder().field(new HighlightBuilder.Field("searchText").highlighterType(highlightType)))
                .get();
        assertHitCount(searchResponse, 1);
        assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("child-id"));
        highlightField = searchResponse.getHits().getAt(0).getHighlightFields().get("searchText");
        assertThat(highlightField.getFragments()[0].string(), equalTo("quick brown <em>fox</em>"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:ChildQuerySearchIT.java

示例13: doSearch

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
private SearchResult doSearch(SearchSourceBuilder searchSourceBuilder, SearchQuery searchQuery) {
	if (searchQuery.getFilter() != null) {
		searchSourceBuilder.postFilter(searchQuery.getFilter());
	}

	if (!isEmpty(searchQuery.getElasticsearchSorts())) {
		for (SortBuilder sort : searchQuery.getElasticsearchSorts()) {
			searchSourceBuilder.sort(sort);
		}
	}

	if (searchQuery.getHighlightFields() != null) {
		HighlightBuilder highlighter = SearchSourceBuilder.highlight();
		for (HighlightBuilder.Field highlightField : searchQuery.getHighlightFields()) {
			highlighter.field(highlightField);
		}
		searchSourceBuilder.highlighter(highlighter);
	}

	if (!isEmpty(searchQuery.getAggregations())) {
		for (AbstractAggregationBuilder aggregationBuilder : searchQuery.getAggregations()) {
			searchSourceBuilder.aggregation(aggregationBuilder);
		}
	}

	if (!isEmpty(searchQuery.getIndicesBoost())) {
		for (IndexBoost indexBoost : searchQuery.getIndicesBoost()) {
			searchSourceBuilder.indexBoost(indexBoost.getIndexName(), indexBoost.getBoost());
		}
	}

	if (!searchQuery.getScriptFields().isEmpty()) {
		for (ScriptField scriptedField : searchQuery.getScriptFields()) {
			searchSourceBuilder.scriptField(scriptedField.fieldName(), scriptedField.script());
		}
	}

	return executeSearch(searchQuery, searchSourceBuilder.query(searchQuery.getQuery()));
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:40,代码来源:JestElasticsearchTemplate.java

示例14: testHighlight

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
@Test
public void testHighlight() throws Exception {
    final String field = "url_highlight_test";
    Map<String, String> docContent = new HashMap<>();
    final String url = "http://www.foo.bar.com:8080/baz/bat?bob=blah";
    docContent.put(field, url);
    client().prepareIndex(INDEX, TYPE).setSource(docContent).get();
    refresh(INDEX);

    SearchResponse response = client().prepareSearch(INDEX).setQuery(QueryBuilders.matchQuery(field, "www.foo.bar.com:8080"))
            .highlighter(new HighlightBuilder().preTags("<b>").postTags("</b>").field("*").forceSource(true))
            .get();

    SearchHit[] hits = response.getHits().getHits();
    assertThat(hits.length, equalTo(1));

    SearchHit hit = hits[0];
    Map<String, Object> source = hit.getSource();
    assertThat(source.size(), equalTo(1));
    assertThat(source, hasKey(field));
    assertThat("URL was stored correctly", source.get(field), equalTo(url));
    assertThat(hit.highlightFields(), hasKey(field));
    HighlightField highlightField = hit.highlightFields().get(field);
    Text[] fragments = highlightField.getFragments();
    assertThat(fragments.length, equalTo(1));
    Text fragment = fragments[0];
    assertThat("URL was highlighted correctly", fragment.string(), equalTo("http://<b>www.foo.bar.com</b>:<b>8080</b>/baz/bat?bob=blah"));
}
 
开发者ID:jlinn,项目名称:elasticsearch-analysis-url,代码行数:29,代码来源:URLTokenizerIntegrationTest.java

示例15: verifyHitHighlightingInteractions

import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; //导入依赖的package包/类
private void verifyHitHighlightingInteractions(SearchRequestBuilder searchRequestBuilder, boolean isHitHighlightingEnabled, Set<String> match)
    throws IOException
{
    if (isHitHighlightingEnabled)
    {
        // verify interactions with the helpers which is required to fetch highlighting config
        verify(jsonHelper, times(4)).unmarshallJsonToObject(eq(Map.class), any(String.class));
        verify(jsonHelper).unmarshallJsonToObject(eq(IndexSearchHighlightFields.class), any(String.class));
        verify(configurationHelper, times(3)).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_POSTTAGS);
        verify(configurationHelper, times(3)).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_PRETAGS);
        if (match != null && match.contains(MATCH_COLUMN))
        {
            verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_COLUMN_MATCH_HIGHLIGHT_FIELDS);
        }
        else
        {
            verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_FIELDS);
        }
    }
    else
    {
        // verify highlighting is not added to the query if not highlighting is disabled
        verify(searchRequestBuilder, times(0)).highlighter(any(HighlightBuilder.class));

        // verify highlighting-specific configuration values are not fetched if highlighting is disabled
        verify(configurationHelper, times(0)).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_POSTTAGS);
        verify(configurationHelper, times(0)).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_PRETAGS);
        verify(configurationHelper, times(0)).getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_FIELDS);
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:31,代码来源:IndexSearchDaoTest.java


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