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();
}
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();
}
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")));
}
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());
}
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();
}
Aggregations