Search in sources :

Example 1 with HighlightQueryProperty

use of com.enonic.xp.query.highlight.HighlightQueryProperty 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 HighlightQueryProperty

use of com.enonic.xp.query.highlight.HighlightQueryProperty 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 HighlightQueryProperty

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

the class ElasticHighlightQueryBuilderFactory method create.

public ElasticHighlightQuery create(final HighlightQuery highlightQuery) {
    if (highlightQuery == null) {
        return ElasticHighlightQuery.empty();
    }
    ElasticHighlightQuery.Builder result = ElasticHighlightQuery.create().settings(highlightQuery.getSettings());
    for (HighlightQueryProperty highlightQueryProperty : highlightQuery.getProperties()) {
        final String normalizedFieldName = IndexFieldNameNormalizer.normalize(highlightQueryProperty.getName());
        final String normalizedFieldNameWithPostFix = normalizedFieldName + IndexValueType.INDEX_VALUE_TYPE_SEPARATOR + "_*";
        final HighlightBuilder.Field rawHighlightField = createField(normalizedFieldName, highlightQueryProperty);
        final HighlightBuilder.Field analyzedHighlightField = createField(normalizedFieldNameWithPostFix, highlightQueryProperty);
        result.addField(rawHighlightField);
        result.addField(analyzedHighlightField);
    }
    return result.build();
}
Also used : HighlightQueryProperty(com.enonic.xp.query.highlight.HighlightQueryProperty) ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) HighlightBuilder(org.elasticsearch.search.highlight.HighlightBuilder)

Aggregations

HighlightQueryProperty (com.enonic.xp.query.highlight.HighlightQueryProperty)3 HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)2 HighlightQuerySettings (com.enonic.xp.query.highlight.HighlightQuerySettings)2 Map (java.util.Map)2 ElasticHighlightQuery (com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery)1 HighlightBuilder (org.elasticsearch.search.highlight.HighlightBuilder)1