Search in sources :

Example 1 with FeedMetadataSearchResultData

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

the class ElasticSearchRestSearchResultTransform method getFeedMetadataSearchResultData.

private FeedMetadataSearchResultData getFeedMetadataSearchResultData(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 TBA_CATEGORY = "tba:category";
    final String TBA_TAGS = "tba:tags";
    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 TBA_CATEGORY_NEW_DESCRIPTION = "Category";
    final String TBA_TAGS_NEW_DESCRIPTION = "Tags";
    final String SPACE_STRING = " ";
    FeedMetadataSearchResultData feedMetadataSearchResultData = new FeedMetadataSearchResultData();
    List<Pair> highlightsList = new ArrayList<>();
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_SYSTEM_NAME, EMPTY_STRING).equals(EMPTY_STRING)) {
        feedMetadataSearchResultData.setFeedSystemName(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_SYSTEM_NAME, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_TITLE, EMPTY_STRING).equals(EMPTY_STRING)) {
        feedMetadataSearchResultData.setFeedTitle(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_TITLE, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_DESCRIPTION, EMPTY_STRING).equals(EMPTY_STRING)) {
        feedMetadataSearchResultData.setFeedDescription(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(JCR_DESCRIPTION, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_CATEGORY, EMPTY_STRING).equals(EMPTY_STRING)) {
        feedMetadataSearchResultData.setFeedCategoryId(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_CATEGORY, EMPTY_STRING).toString());
    }
    if (!elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_TAGS, EMPTY_STRING).equals(EMPTY_STRING)) {
        feedMetadataSearchResultData.setFeedTags(Arrays.asList(elasticSearchRestSearchHit.findValueForKeyInSourceWithDefault(TBA_TAGS, EMPTY_STRING).toString().split(SPACE_STRING)));
    }
    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_TAGS:
                key = TBA_TAGS_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case TBA_CATEGORY:
                key = TBA_CATEGORY_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case TBA_SYSTEM_NAME:
                key = TBA_SYSTEM_NAME_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            default:
                break;
        }
        if (includeHighlight) {
            highlightsList.add(new Pair(key, highlightPair.getValue()));
        }
    }
    feedMetadataSearchResultData.setHighlights(highlightsList);
    Map<String, Object> rawData = new HashMap<>();
    rawData.put(RAW_DATA_KEY, elasticSearchRestSearchHit.getRawHit());
    feedMetadataSearchResultData.setRawData(rawData);
    feedsMetadataTypeResultCount += 1L;
    return feedMetadataSearchResultData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeedMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Example 2 with FeedMetadataSearchResultData

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

the class ElasticSearchSearchResultTransform method getFeedMetadataSearchResultData.

private FeedMetadataSearchResultData getFeedMetadataSearchResultData(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_CATEGORY = "tba:category";
    final String TBA_TAGS = "tba:tags";
    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 TBA_CATEGORY_NEW_DESCRIPTION = "Category";
    final String TBA_TAGS_NEW_DESCRIPTION = "Tags";
    final String SPACE_STRING = " ";
    Map<String, Object> searchHitSourceMap = searchHit.sourceAsMap();
    FeedMetadataSearchResultData feedMetadataSearchResultData = new FeedMetadataSearchResultData();
    List<Pair> highlightsList = new ArrayList<>();
    if (searchHitSourceMap.containsKey(TBA_SYSTEM_NAME)) {
        feedMetadataSearchResultData.setFeedSystemName(searchHitSourceMap.get(TBA_SYSTEM_NAME).toString());
    }
    if (searchHitSourceMap.containsKey(JCR_TITLE)) {
        feedMetadataSearchResultData.setFeedTitle(searchHitSourceMap.get(JCR_TITLE).toString());
    }
    if (searchHitSourceMap.containsKey(JCR_DESCRIPTION)) {
        feedMetadataSearchResultData.setFeedDescription(searchHitSourceMap.get(JCR_DESCRIPTION).toString());
    }
    if (searchHitSourceMap.containsKey(TBA_CATEGORY)) {
        feedMetadataSearchResultData.setFeedCategoryId(searchHitSourceMap.get(TBA_CATEGORY).toString());
    }
    if (searchHitSourceMap.containsKey(TBA_TAGS)) {
        feedMetadataSearchResultData.setFeedTags(Arrays.asList(searchHitSourceMap.get(TBA_TAGS).toString().split(SPACE_STRING)));
    }
    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_TAGS:
                key = TBA_TAGS_NEW_DESCRIPTION;
                includeHighlight = true;
                break;
            case TBA_CATEGORY:
                key = TBA_CATEGORY_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()));
        }
    }
    feedMetadataSearchResultData.setHighlights(highlightsList);
    feedMetadataSearchResultData.setRawData(searchHit.getSource());
    feedsMetadataTypeResultCount += 1L;
    return feedMetadataSearchResultData;
}
Also used : ArrayList(java.util.ArrayList) HighlightField(org.elasticsearch.search.highlight.HighlightField) HashMap(java.util.HashMap) Map(java.util.Map) FeedMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData) Pair(com.thinkbiganalytics.search.rest.model.Pair)

Aggregations

FeedMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData)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