Search in sources :

Example 26 with HighlightBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder in project graylog2-server by Graylog2.

the class SearchesAdapterES6 method applyHighlighting.

private void applyHighlighting(SearchSourceBuilder searchSourceBuilder, ScrollCommand scrollCommand) {
    if (scrollCommand.highlight() && configuration.isAllowHighlighting()) {
        final HighlightBuilder highlightBuilder = new HighlightBuilder().requireFieldMatch(false).field("*").fragmentSize(0).numOfFragments(0);
        searchSourceBuilder.highlighter(highlightBuilder);
    }
}
Also used : HighlightBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)

Example 27 with HighlightBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder in project graylog2-server by Graylog2.

the class SearchesAdapterES6 method standardSearchRequest.

private SearchSourceBuilder standardSearchRequest(String query, int limit, int offset, TimeRange range, String filter, Sorting sort, boolean highlight) {
    if (query == null || query.trim().isEmpty()) {
        query = "*";
    }
    final QueryBuilder queryBuilder;
    if ("*".equals(query.trim())) {
        queryBuilder = matchAllQuery();
    } else {
        queryBuilder = queryStringQuery(query).allowLeadingWildcard(configuration.isAllowLeadingWildcardSearches());
    }
    final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(QueryBuilders.boolQuery().must(queryBuilder).filter(standardFilters(range, filter)));
    if (offset >= 0) {
        searchSourceBuilder.from(offset);
    }
    if (limit > 0) {
        searchSourceBuilder.size(limit);
    }
    if (sort != null) {
        searchSourceBuilder.sort(sort.getField(), sortOrderMapper.fromSorting(sort));
    }
    if (highlight && configuration.isAllowHighlighting()) {
        final HighlightBuilder highlightBuilder = new HighlightBuilder().requireFieldMatch(false).field("*").fragmentSize(0).numOfFragments(0);
        searchSourceBuilder.highlighter(highlightBuilder);
    }
    return searchSourceBuilder;
}
Also used : QueryBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder) HighlightBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)

Example 28 with HighlightBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder in project graylog2-server by Graylog2.

the class SearchRequestFactory method applyHighlighting.

private void applyHighlighting(SearchSourceBuilder searchSourceBuilder) {
    if (allowHighlighting) {
        final HighlightBuilder highlightBuilder = new HighlightBuilder().requireFieldMatch(false).field("*").fragmentSize(0).numOfFragments(0);
        searchSourceBuilder.highlighter(highlightBuilder);
    }
}
Also used : HighlightBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)

Aggregations

HighlightBuilder (org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)23 SearchResponse (org.elasticsearch.action.search.SearchResponse)16 SearchHits (org.elasticsearch.search.SearchHits)7 ArrayList (java.util.ArrayList)5 Script (org.elasticsearch.script.Script)5 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 Map (java.util.Map)4 InnerHitBuilder (org.elasticsearch.index.query.InnerHitBuilder)4 SearchHit (org.elasticsearch.search.SearchHit)4 HighlightField (org.elasticsearch.search.fetch.subphase.highlight.HighlightField)4 HashMap (java.util.HashMap)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3 SearchHitField (org.elasticsearch.search.SearchHitField)3 IOException (java.io.IOException)2 Date (java.util.Date)2 List (java.util.List)2 ServiceResponse (net.yacy.grid.http.ServiceResponse)2 ElasticsearchClient (net.yacy.grid.io.index.ElasticsearchClient)2 Sort (net.yacy.grid.io.index.Sort)2