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


Java HighlightField类代码示例

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


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

示例1: PercolateShardResponse

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
public PercolateShardResponse(BytesRef[] matches, List<Map<String, HighlightField>> hls, long count, float[] scores, PercolateContext context, ShardId shardId) {
    super(shardId);
    this.matches = matches;
    this.hls = hls;
    this.count = count;
    this.scores = scores;
    this.percolatorTypeId = context.percolatorTypeId;
    this.requestedSize = context.size();
    QuerySearchResult result = context.queryResult();
    if (result != null) {
        if (result.aggregations() != null) {
            this.aggregations = (InternalAggregations) result.aggregations();
        }
        this.pipelineAggregators = result.pipelineAggregators();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:PercolateShardResponse.java

示例2: mapEntity

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) {
	T t = mapEntity(source , clazz) ;
	
	Map<String, HighlightField> highlightFields = hit.getHighlightFields();
	HighlightField highlightNameField = highlightFields.get("title");
	HighlightField contentHightlightField = highlightFields.get("content");
	try {
		if(highlightNameField!=null&&highlightNameField.fragments()!=null){
			PropertyUtils.setProperty(t, "title" , highlightNameField.fragments()[0].string());
		}
		if(contentHightlightField!=null){
			PropertyUtils.setProperty(t, "content" , contentHightlightField.fragments()[0].string());
		}
		PropertyUtils.setProperty(t, "id" , hit.getId());
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		e.printStackTrace();
	} 
	return t;
}
 
开发者ID:uckefu,项目名称:uckefu,代码行数:20,代码来源:UKResultMapper.java

示例3: highLightResult

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
/**
 * 对搜索命中结果做高亮
 *
 * @param json
 * @param hit
 * @param highLigthFieldName
 */
private void highLightResult (JSONObject json, SearchHit hit, String highLigthFieldName) {
    //获取对应的高亮域
    Map<String, HighlightField> result = hit.highlightFields();
    //从设定的高亮域中取得指定域
    HighlightField hlField = result.get(highLigthFieldName);
    if (Check.NuNObj(hlField)) {
        return;
    }
    //取得定义的高亮标签
    Text[] hlTexts = hlField.fragments();
    if (Check.NuNObject(hlTexts)) {
        return;
    }
    //为title串值增加自定义的高亮标签
    StringBuffer hlTextsFiled = new StringBuffer();
    for (Text text : hlTexts) {
        hlTextsFiled.append(text);
    }
    //如果高亮域内有fragments 反回的数据不为空字符串
    if (!Check.NuNStrStrict(hlTextsFiled.toString())) {
        json.put(highLigthFieldName, hlTextsFiled);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:31,代码来源:EsQuery.java

示例4: addIdIndexAndType

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
/**
 * Adds _id, _index and/or _type to the current row
 * @param idIndexTypeScore = String[]{_id, _index, _type}
 * @param head
 * @param row
 */
private void addIdIndexAndType(String id, String index, String type, Float score, Map<String, HighlightField> highlights, Heading head, List<Object> row){
	if(id != null && head.hasAllCols() || head.hasLabel(Heading.ID)){
		row.set( head.getColumnByLabel(Heading.ID).getIndex(), id);
	}
	if(index != null && head.hasAllCols() || head.hasLabel(Heading.INDEX)){
		row.set( head.getColumnByLabel(Heading.INDEX).getIndex(), index);
	}
	if(type != null && head.hasAllCols() || head.hasLabel(Heading.TYPE)){
		row.set( head.getColumnByLabel(Heading.TYPE).getIndex(), type);
	}
	if(score != null && head.hasLabel(Heading.SCORE)){
		row.set( head.getColumnByLabel(Heading.SCORE).getIndex(), score);
	}
	if(highlights != null){
		for(String field : highlights.keySet()){
			Column col = head.getColumnByNameAndOp(field, Operation.HIGHLIGHT);
			if(col == null) continue;
			List<Object> fragments = new ArrayList<Object>();
			for(Text fragment : highlights.get(field).getFragments()) fragments.add(fragment.toString());
			row.set(col.getIndex(), new ESArray(fragments));
		}
	}
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:30,代码来源:SearchHitParser.java

示例5: getHighlight

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
/**
 * 
 * @param hit
 * @param seach_fileds
 * @return
 */
public static Map<String, Object> getHighlight(SearchHit hit, List<String> seach_fileds) {
    Map<String, Object> result = new HashMap<String, Object>();
    Map<String, HighlightField> highlights = hit.highlightFields();
    for (String filed : seach_fileds) {
        HighlightField highlight = highlights.get(filed);
        if (null == highlight) {
            continue;
        }
        StringBuffer sb = new StringBuffer();
        Text[] fragments = highlight.fragments();
        for (Text fragment : fragments) {
            sb.append(fragment);
        }
        result.put(filed + "_HIGH", sb.toString());
    }
    return result;

}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:25,代码来源:EsHighLight.java

示例6: getHighlightsFromResult

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
private static Map<String, HighlightResult> getHighlightsFromResult(SearchHits hits) {
    final HashMap<String, HighlightResult> highlights = new HashMap<>();
    for (final SearchHit hit : hits) {
        final HighlightResult result = new HighlightResult(new HashMap<String, List<String>>());
        final Collection<HighlightField> highlightFields = hit.getHighlightFields().values();
        for (final HighlightField entry : highlightFields) {
            final List<String> fragments = new ArrayList<>();
            final Text[] frags = entry.fragments();
            for (final Text t : frags) {
                fragments.add(t.toString());
            }
            result.putToResults(entry.getName(), fragments);
        }
        highlights.put(hit.getId(), result);
    }
    return highlights;
}
 
开发者ID:ezbake,项目名称:ezelastic,代码行数:18,代码来源:ElasticClient.java

示例7: highlightFields

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
@Override
public Map<String, HighlightField> highlightFields() {
    if (highlightFields == null) {
        return ImmutableMap.of();
    }
    return this.highlightFields;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:InternalSearchHit.java

示例8: Match

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
/**
 * Constructor only for internal usage.
 */
public Match(Text index, Text id, float score, Map<String, HighlightField> hl) {
    this.id = id;
    this.score = score;
    this.index = index;
    this.hl = hl;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:PercolateResponse.java

示例9: readFrom

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
    id = in.readText();
    index = in.readText();
    score = in.readFloat();
    int size = in.readVInt();
    if (size > 0) {
        hl = new HashMap<>(size);
        for (int j = 0; j < size; j++) {
            hl.put(in.readString(), HighlightField.readHighlightField(in));
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:PercolateResponse.java

示例10: writeTo

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeText(id);
    out.writeText(index);
    out.writeFloat(score);
    if (hl != null) {
        out.writeVInt(hl.size());
        for (Map.Entry<String, HighlightField> entry : hl.entrySet()) {
            out.writeString(entry.getKey());
            entry.getValue().writeTo(out);
        }
    } else {
        out.writeVInt(0);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:PercolateResponse.java

示例11: readFrom

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    percolatorTypeId = in.readByte();
    requestedSize = in.readVInt();
    count = in.readVLong();
    matches = new BytesRef[in.readVInt()];
    for (int i = 0; i < matches.length; i++) {
        matches[i] = in.readBytesRef();
    }
    scores = new float[in.readVInt()];
    for (int i = 0; i < scores.length; i++) {
        scores[i] = in.readFloat();
    }
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        int mSize = in.readVInt();
        Map<String, HighlightField> fields = new HashMap<>();
        for (int j = 0; j < mSize; j++) {
            fields.put(in.readString(), HighlightField.readHighlightField(in));
        }
        hls.add(fields);
    }
    aggregations = InternalAggregations.readOptionalAggregations(in);
    if (in.readBoolean()) {
        int pipelineAggregatorsSize = in.readVInt();
        List<SiblingPipelineAggregator> pipelineAggregators = new ArrayList<>(pipelineAggregatorsSize);
        for (int i = 0; i < pipelineAggregatorsSize; i++) {
            BytesReference type = in.readBytesReference();
            PipelineAggregator pipelineAggregator = PipelineAggregatorStreams.stream(type).readResult(in);
            pipelineAggregators.add((SiblingPipelineAggregator) pipelineAggregator);
        }
        this.pipelineAggregators = pipelineAggregators;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:PercolateShardResponse.java

示例12: writeTo

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(percolatorTypeId);
    out.writeVLong(requestedSize);
    out.writeVLong(count);
    out.writeVInt(matches.length);
    for (BytesRef match : matches) {
        out.writeBytesRef(match);
    }
    out.writeVLong(scores.length);
    for (float score : scores) {
        out.writeFloat(score);
    }
    out.writeVInt(hls.size());
    for (Map<String, HighlightField> hl : hls) {
        out.writeVInt(hl.size());
        for (Map.Entry<String, HighlightField> entry : hl.entrySet()) {
            out.writeString(entry.getKey());
            entry.getValue().writeTo(out);
        }
    }
    out.writeOptionalStreamable(aggregations);
    if (pipelineAggregators == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeVInt(pipelineAggregators.size());
        for (PipelineAggregator pipelineAggregator : pipelineAggregators) {
            out.writeBytesReference(pipelineAggregator.type().stream());
            pipelineAggregator.writeTo(out);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:PercolateShardResponse.java

示例13: termQuery

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
public static void termQuery(Client client ) {
		SearchResponse res = null;
		QueryBuilder qb = QueryBuilders
				.termQuery("title","article");
		
//		QueryBuilder qb = QueryBuilders
//				.termsQuery("title","article","relevence");
		
		res = client.prepareSearch("search_test")
				.setTypes("article")
				.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
				.setQuery(qb)
				.addHighlightedField("title")
				.setHighlighterPreTags("<span class='searchKey'>")
				.setHighlighterPostTags("</san>")
				.setFrom(0)
				.setSize(10)
				.execute().actionGet();
		for (SearchHit hit: res.getHits()) {
			Map<String, HighlightField> result = hit.highlightFields();
			HighlightField highlightedSummary = result.get("title");
			Text[] titleTexts = highlightedSummary.getFragments();
			String allFragments = "";
			for (Text text: titleTexts){
				allFragments += text;
			}
			System.out.println(result);
			System.out.println(allFragments);		
		}
		
		// on shutdown
		client.close();
		
		//common terms query
	}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:36,代码来源:QueryTest.java

示例14: getHighlightedFragments

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
/**
 * 検索キーワードにマッチした箇所をハイライトした値へのStreamを返す.
 * @see Stream
 * @param fieldName フィールド名
 * @return {@link Stream}
 */
public Stream<String> getHighlightedFragments(String fieldName) {
    HighlightField field = hit.getHighlightFields().get(fieldName);
    if (field != null) {
        Stream<Text> s = Arrays.stream(field.getFragments());
        return s.map(t -> t.string());
    }

    return new ArrayList<String>().stream();
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:16,代码来源:ElasticsearchSearchResultRecord.java

示例15: getHighlight

import org.elasticsearch.search.highlight.HighlightField; //导入依赖的package包/类
private Map<String, List<String>> getHighlight(Set<Map.Entry<String, HighlightField>> entrySet) {
	Map<String, List<String>> highlight = new HashMap<>();

	for (Map.Entry<String, HighlightField> highlightField : entrySet) {
		List<String> fragments = new ArrayList<>();
		for (Text text : highlightField.getValue().fragments()) {
			fragments.add(text.string());
		}
		highlight.put(highlightField.getKey(), fragments);
	}

	return highlight;
}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:14,代码来源:SearchService.java


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