Search in sources :

Example 1 with CategoryMetadataSearchResultData

use of com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData in project kylo by Teradata.

the class ElasticSearchSearchResultTransform method getCategoryMetadataSearchResultData.

private CategoryMetadataSearchResultData getCategoryMetadataSearchResultData(SearchHit searchHit) {
    // jcr has no notion of null-valued property. So, account for the situation when there is no tag present.
    final String TBA_SYSTEM_NAME = "tba:systemName";
    final String JCR_TITLE = "jcr:title";
    final String JCR_DESCRIPTION = "jcr:description";
    final String TBA_SYSTEM_NAME_NEW_DESCRIPTION = "System name (Kylo)";
    final String JCR_TITLE_NEW_DESCRIPTION = "Title";
    final String JCR_DESCRIPTION_NEW_DESCRIPTION = "Description";
    Map<String, Object> searchHitSourceMap = searchHit.sourceAsMap();
    CategoryMetadataSearchResultData categoryMetadataSearchResultData = new CategoryMetadataSearchResultData();
    List<Pair> highlightsList = new ArrayList<>();
    if (searchHitSourceMap.containsKey(TBA_SYSTEM_NAME)) {
        categoryMetadataSearchResultData.setCategorySystemName(searchHitSourceMap.get(TBA_SYSTEM_NAME).toString());
    }
    if (searchHitSourceMap.containsKey(JCR_TITLE)) {
        categoryMetadataSearchResultData.setCategoryTitle(searchHitSourceMap.get(JCR_TITLE).toString());
    }
    if (searchHitSourceMap.containsKey(JCR_DESCRIPTION)) {
        categoryMetadataSearchResultData.setCategoryDescription(searchHitSourceMap.get(JCR_DESCRIPTION).toString());
    }
    Map<String, HighlightField> highlights = searchHit.getHighlightFields();
    for (Map.Entry<String, HighlightField> entry : highlights.entrySet()) {
        String key = entry.getKey();
        Boolean includeHighlight = false;
        switch(key) {
            case JCR_TITLE:
                key = JCR_TITLE_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case JCR_DESCRIPTION:
                key = JCR_DESCRIPTION_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case TBA_SYSTEM_NAME:
                key = TBA_SYSTEM_NAME_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
        }
        if (includeHighlight && entry.getValue().getFragments().length >= 1) {
            highlightsList.add(new Pair(key, entry.getValue().getFragments()[0].toString()));
        }
    }
    categoryMetadataSearchResultData.setHighlights(highlightsList);
    categoryMetadataSearchResultData.setRawData(searchHit.getSource());
    categoriesMetadataTypeResultCount += 1L;
    return categoryMetadataSearchResultData;
}
Also used : ArrayList(java.util.ArrayList) CategoryMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData) HighlightField(org.elasticsearch.search.highlight.HighlightField) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Example 2 with CategoryMetadataSearchResultData

use of com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData in project kylo by Teradata.

the class ElasticSearchRestSearchResultTransform method getCategoryMetadataSearchResultData.

private CategoryMetadataSearchResultData getCategoryMetadataSearchResultData(ElasticSearchRestSearchHit elasticSearchRestSearchHit) {
    // jcr has no notion of null-valued property. So, account for the situation when there is no tag present.
    final String TBA_SYSTEM_NAME = "tba:systemName";
    final String JCR_TITLE = "jcr:title";
    final String JCR_DESCRIPTION = "jcr:description";
    final String USR_PROPERTIES = "usr:properties";
    final String TBA_SYSTEM_NAME_NEW_DESCRIPTION = "System name (Kylo)";
    final String JCR_TITLE_NEW_DESCRIPTION = "Title";
    final String JCR_DESCRIPTION_NEW_DESCRIPTION = "Description";
    final String USR_PROPERTIES_NEW_DESCRIPTION = "User properties";
    CategoryMetadataSearchResultData categoryMetadataSearchResultData = new CategoryMetadataSearchResultData();
    List<Pair> highlightsList = new ArrayList<>();
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_SYSTEM_NAME, EMPTY_STRING).equals(EMPTY_STRING)) {
        categoryMetadataSearchResultData.setCategorySystemName(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_SYSTEM_NAME, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_TITLE, EMPTY_STRING).equals(EMPTY_STRING)) {
        categoryMetadataSearchResultData.setCategoryTitle(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_TITLE, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_DESCRIPTION, EMPTY_STRING).equals(EMPTY_STRING)) {
        categoryMetadataSearchResultData.setCategoryDescription(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_DESCRIPTION, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(USR_PROPERTIES, EMPTY_STRING).equals(EMPTY_STRING)) {
        categoryMetadataSearchResultData.setUserProperties(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(USR_PROPERTIES, EMPTY_STRING).toString());
    }
    for (Pair highlightPair : elasticSearchRestSearchHit.getHighlights()) {
        String key = highlightPair.getKey();
        Boolean includeHighlight = false;
        switch(key) {
            case JCR_TITLE:
                key = JCR_TITLE_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case JCR_DESCRIPTION:
                key = JCR_DESCRIPTION_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case TBA_SYSTEM_NAME:
                key = TBA_SYSTEM_NAME_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case USR_PROPERTIES:
                key = USR_PROPERTIES_NEW_DESCRIPTION;
                includeHighlight = true;
            default:
                break;
        }
        if (includeHighlight) {
            if (key.equals(USR_PROPERTIES_NEW_DESCRIPTION)) {
                highlightsList.add(new Pair(key, getRenderPropertySearchResultHtmlAsString(highlightPair.getValue().toString())));
            } else {
                highlightsList.add(new Pair(key, highlightPair.getValue()));
            }
        }
    }
    categoryMetadataSearchResultData.setHighlights(highlightsList);
    Map<String, Object> rawData = new HashMap<>();
    rawData.put(RAW_DATA_KEY, elasticSearchRestSearchHit.getRawHit());
    categoryMetadataSearchResultData.setRawData(rawData);
    categoriesMetadataTypeResultCount += 1L;
    return categoryMetadataSearchResultData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CategoryMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Aggregations

CategoryMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData)2 Pair (com.thinkbiganalytics.search.rest.model.Pair)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)1 HighlightField (org.elasticsearch.search.highlight.HighlightField)1