Search in sources :

Example 1 with HighlightQuery

use of com.enonic.xp.query.highlight.HighlightQuery in project xp by enonic.

the class QueryHighlightParams method getHighlightQuery.

HighlightQuery getHighlightQuery(final Map<String, Object> highlightMap) {
    if (highlightMap == null) {
        return HighlightQuery.empty();
    }
    final HighlightQuerySettings settings = fillQuerySettings(HighlightQuerySettings.create(), highlightMap).build();
    final HighlightQuery.Builder highlightQuery = HighlightQuery.create().settings(settings);
    final Map<String, Object> propertiesMap = (Map<String, Object>) highlightMap.get("properties");
    if (propertiesMap == null) {
        return HighlightQuery.empty();
    }
    propertiesMap.forEach((name, propertyMap) -> {
        final HighlightQueryProperty highlightQueryProperty = highlightPropertyFromParams(name, (Map<String, Object>) propertyMap);
        highlightQuery.property(highlightQueryProperty);
    });
    return highlightQuery.build();
}
Also used : HighlightQueryProperty(com.enonic.xp.query.highlight.HighlightQueryProperty) HighlightQuerySettings(com.enonic.xp.query.highlight.HighlightQuerySettings) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery) Map(java.util.Map)

Example 2 with HighlightQuery

use of com.enonic.xp.query.highlight.HighlightQuery in project xp by enonic.

the class QueryHighlightParams method getHighlightQuery.

HighlightQuery getHighlightQuery(final Map<String, Object> highlightMap) {
    if (highlightMap == null) {
        return HighlightQuery.empty();
    }
    final HighlightQuerySettings settings = fillQuerySettings(HighlightQuerySettings.create(), highlightMap).build();
    final HighlightQuery.Builder highlightQuery = HighlightQuery.create().settings(settings);
    final Map<String, Object> propertiesMap = (Map<String, Object>) highlightMap.get("properties");
    if (propertiesMap == null) {
        return HighlightQuery.empty();
    }
    propertiesMap.forEach((name, propertyMap) -> {
        final HighlightQueryProperty highlightQueryProperty = highlightPropertyFromParams(name, (Map<String, Object>) propertyMap);
        highlightQuery.property(highlightQueryProperty);
    });
    return highlightQuery.build();
}
Also used : HighlightQueryProperty(com.enonic.xp.query.highlight.HighlightQueryProperty) HighlightQuerySettings(com.enonic.xp.query.highlight.HighlightQuerySettings) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery) Map(java.util.Map)

Example 3 with HighlightQuery

use of com.enonic.xp.query.highlight.HighlightQuery in project xp by enonic.

the class ElasticHighlightQueryBuilderFactoryTest method create.

@Test
public void create() {
    final HighlightQuery query = HighlightQuery.create().property(HighlightQueryProperty.create("propertyToHighlight").build()).build();
    final ElasticHighlightQuery elasticHighlightQuery = highlightQueryBuilderFactory.create(query);
    assertNotNull(elasticHighlightQuery);
    assertEquals(2, elasticHighlightQuery.getFields().size());
    final List<String> names = elasticHighlightQuery.getFields().stream().map(HighlightBuilder.Field::name).collect(Collectors.toList());
    assertTrue(names.containsAll(List.of("propertytohighlight._*", "propertytohighlight")));
}
Also used : ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery) ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) HighlightBuilder(org.elasticsearch.search.highlight.HighlightBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with HighlightQuery

use of com.enonic.xp.query.highlight.HighlightQuery in project xp by enonic.

the class ElasticHighlightQueryBuilderFactoryTest method create_with_settings.

@Test
public void create_with_settings() {
    final HighlightQuery query = HighlightQuery.create().property(HighlightQueryProperty.create("propertyToHighlight").build()).settings(HighlightQuerySettings.create().encoder(Encoder.HTML).fragmenter(Fragmenter.SIMPLE).fragmentSize(1).noMatchSize(2).numOfFragments(3).order(Order.SCORE).addPreTags(List.of("<a>", "<b>")).addPostTags(List.of("<c>", "<d>")).requireFieldMatch(true).tagsSchema(TagsSchema.STYLED).build()).build();
    final ElasticHighlightQuery elasticHighlightQuery = highlightQueryBuilderFactory.create(query);
    assertNotNull(elasticHighlightQuery);
    assertEquals(2, elasticHighlightQuery.getFields().size());
    assertEquals(Encoder.HTML, elasticHighlightQuery.getEncoder());
    assertEquals(1, (int) elasticHighlightQuery.getFragmentSize());
    assertEquals(2, (int) elasticHighlightQuery.getNoMatchSize());
    assertEquals(3, (int) elasticHighlightQuery.getNumOfFragments());
    assertEquals(List.of("<a>", "<b>"), elasticHighlightQuery.getPreTags());
    assertEquals(List.of("<c>", "<d>"), elasticHighlightQuery.getPostTags());
    assertEquals(true, elasticHighlightQuery.getRequireFieldMatch());
    assertEquals(TagsSchema.STYLED, elasticHighlightQuery.getTagsSchema());
}
Also used : ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery) ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) Test(org.junit.jupiter.api.Test)

Example 5 with HighlightQuery

use of com.enonic.xp.query.highlight.HighlightQuery in project xp by enonic.

the class ContentQueryTest method createTestQuery.

private ContentQuery createTestQuery() {
    final GeoDistanceAggregationQuery query1 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final GeoDistanceAggregationQuery query2 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final GeoDistanceAggregationQuery query3 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final HighlightQuery highlightQuery = HighlightQuery.create().property(HighlightQueryProperty.create("propertyToHighlight").build()).settings(HighlightQuerySettings.create().encoder(Encoder.HTML).fragmenter(Fragmenter.SIMPLE).fragmentSize(1).noMatchSize(2).numOfFragments(3).order(Order.SCORE).addPreTags(List.of("<a>", "<b>")).addPostTags(List.of("<c>", "<d>")).requireFieldMatch(true).tagsSchema(TagsSchema.STYLED).build()).build();
    final ContentQuery.Builder builder = ContentQuery.create();
    builder.addContentTypeName(ContentTypeName.imageMedia());
    builder.addContentTypeNames(ContentTypeNames.from(ContentTypeName.archiveMedia(), ContentTypeName.dataMedia()));
    builder.aggregationQuery(query1);
    builder.aggregationQueries(Arrays.asList(query2, query3));
    builder.highlight(highlightQuery);
    builder.from(10);
    builder.size(10);
    builder.queryExpr(QueryExpr.from(CompareExpr.eq(FieldExpr.from("name"), ValueExpr.string("testerson"))));
    builder.queryFilter(RangeFilter.create().from(ValueFactory.newDouble(2.0)).to(ValueFactory.newDouble(10.0)).build());
    return builder.build();
}
Also used : GeoDistanceAggregationQuery(com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery) ContentQuery(com.enonic.xp.content.ContentQuery) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery)

Aggregations

HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)7 ContentQuery (com.enonic.xp.content.ContentQuery)2 QueryExpr (com.enonic.xp.query.expr.QueryExpr)2 Filters (com.enonic.xp.query.filter.Filters)2 HighlightQueryProperty (com.enonic.xp.query.highlight.HighlightQueryProperty)2 HighlightQuerySettings (com.enonic.xp.query.highlight.HighlightQuerySettings)2 ElasticHighlightQuery (com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)1 GeoDistanceAggregationQuery (com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery)1 Filter (com.enonic.xp.query.filter.Filter)1 SuggestionQueries (com.enonic.xp.query.suggester.SuggestionQueries)1 ContentTypeNames (com.enonic.xp.schema.content.ContentTypeNames)1 HighlightBuilder (org.elasticsearch.search.highlight.HighlightBuilder)1