Search in sources :

Example 1 with SearchResultData

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

the class ElasticSearchRestSearchResultTransform method transformRestResult.

public SearchResult transformRestResult(String query, int size, int start, ElasticSearchRestSearchResponse restSearchResponse) {
    final String KYLO_DATA = "kylo-data";
    final String KYLO_SCHEMA_METADATA = "kylo-schema-metadata";
    final String KYLO_FEEDS = "kylo-feeds";
    final String KYLO_CATEGORIES = "kylo-categories";
    final String ELASTIC_SEARCH_RC = "Elasticsearch (rc)";
    List<SearchResultData> searchResultData = new ArrayList<>();
    for (ElasticSearchRestSearchHit elasticSearchRestSearchHit : restSearchResponse.getElasticSearchRestSearchHits()) {
        if (elasticSearchRestSearchHit.getIndexName().equals(KYLO_DATA)) {
            searchResultData.add(getTableSearchResultData(elasticSearchRestSearchHit));
        } else if (elasticSearchRestSearchHit.getIndexName().equals(SearchIndex.DATASOURCES)) {
            searchResultData.add(getSchemaSearchResultData(elasticSearchRestSearchHit));
        } else if (elasticSearchRestSearchHit.getIndexName().contains(KYLO_FEEDS)) {
            // This is dependent upon ModeShape configuration. The prefix will remain the same.
            // Hence only checking part of index name
            searchResultData.add(getFeedMetadataSearchResultData(elasticSearchRestSearchHit));
        } else if (elasticSearchRestSearchHit.getIndexName().contains(KYLO_CATEGORIES)) {
            // This is dependent upon ModeShape configuration. The prefix will remain the same.
            // Hence only checking part of index name
            searchResultData.add(getCategoryMetadataSearchResultData(elasticSearchRestSearchHit));
        } else {
            searchResultData.add(getUnknownTypeSearchResultData(elasticSearchRestSearchHit));
        }
    }
    SearchResult elasticSearchRestResult = new SearchResult();
    elasticSearchRestResult.setQuery(query);
    Long totalHits = restSearchResponse.getTotalResults();
    elasticSearchRestResult.setTotalHits(totalHits);
    elasticSearchRestResult.setFrom((long) (start + 1));
    elasticSearchRestResult.setTo((long) (start + size));
    if (totalHits < (start + size)) {
        elasticSearchRestResult.setTo(totalHits);
    }
    if (totalHits == 0) {
        elasticSearchRestResult.setFrom(0L);
    }
    elasticSearchRestResult.setTookInMillis(restSearchResponse.getTookInMillis());
    elasticSearchRestResult.setEngine(ELASTIC_SEARCH_RC);
    elasticSearchRestResult.setSearchResults(searchResultData);
    elasticSearchRestResult.setSearchResultsSummary(getSearchResultSummary());
    return elasticSearchRestResult;
}
Also used : TableSearchResultData(com.thinkbiganalytics.search.rest.model.TableSearchResultData) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) SearchResultData(com.thinkbiganalytics.search.rest.model.SearchResultData) FeedMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData) UnknownTypeSearchResultData(com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData) CategoryMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData) ArrayList(java.util.ArrayList) ElasticSearchRestSearchHit(com.thinkbiganalytics.search.rest.model.es.ElasticSearchRestSearchHit) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult)

Example 2 with SearchResultData

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

the class ElasticSearchSearchResultTransform method transformResult.

public SearchResult transformResult(String query, int size, int start, SearchResponse searchResponse) {
    final String KYLO_DATA = "kylo-data";
    final String KYLO_SCHEMA_METADATA = "kylo-schema-metadata";
    final String KYLO_FEEDS = "kylo-feeds";
    final String KYLO_CATEGORIES = "kylo-categories";
    final String ELASTIC_SEARCH = "Elasticsearch";
    List<SearchResultData> searchResultData = new ArrayList<>();
    for (SearchHit searchHit : searchResponse.getHits().getHits()) {
        if (searchHit.getIndex().equals(KYLO_DATA)) {
            searchResultData.add(getTableSearchResultData(searchHit));
        } else if (searchHit.getIndex().equals(SearchIndex.DATASOURCES)) {
            searchResultData.add(getSchemaSearchResultData(searchHit));
        } else if (searchHit.getIndex().contains(KYLO_FEEDS)) {
            // This is dependent upon ModeShape configuration. The prefix will remain the same.
            // Hence only checking part of index name.
            searchResultData.add(getFeedMetadataSearchResultData(searchHit));
        } else if (searchHit.getIndex().contains(KYLO_CATEGORIES)) {
            // This is dependent upon ModeShape configuration. The prefix will remain the same.
            // Hence only checking part of index name.
            searchResultData.add(getCategoryMetadataSearchResultData(searchHit));
        } else {
            searchResultData.add(getUnknownTypeSearchResultData(searchHit));
        }
    }
    SearchResult elasticSearchResult = new SearchResult();
    elasticSearchResult.setQuery(query);
    elasticSearchResult.setTotalHits(searchResponse.getHits().getTotalHits());
    elasticSearchResult.setFrom((long) (start + 1));
    elasticSearchResult.setTo((long) (start + size));
    if (elasticSearchResult.getTotalHits() < (start + size)) {
        elasticSearchResult.setTo(elasticSearchResult.getTotalHits());
    }
    if (elasticSearchResult.getTotalHits() == 0) {
        elasticSearchResult.setFrom(0L);
    }
    elasticSearchResult.setTookInMillis(searchResponse.getTookInMillis());
    elasticSearchResult.setEngine(ELASTIC_SEARCH);
    elasticSearchResult.setSearchResults(searchResultData);
    elasticSearchResult.setSearchResultsSummary(getSearchResultSummary());
    return elasticSearchResult;
}
Also used : TableSearchResultData(com.thinkbiganalytics.search.rest.model.TableSearchResultData) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) SearchResultData(com.thinkbiganalytics.search.rest.model.SearchResultData) FeedMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData) UnknownTypeSearchResultData(com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData) CategoryMetadataSearchResultData(com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData) SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult)

Example 3 with SearchResultData

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

the class SolrSearchResultTransform method transformResult.

public SearchResult transformResult(String query, int size, int start, QueryResponse solrResponse) {
    final String KYLO_COLLECTION = "kylo_collection";
    final String KYLO_DATA = "kylo-data";
    final String SOLR = "Solr";
    List<SearchResultData> searchResultData = new ArrayList<>();
    for (SolrDocument solrDocument : solrResponse.getResults()) {
        // Have to do this way since solrDocument.getFieldValueMap() does not work as expected.
        Map<String, Object> solrDocumentFieldValueMap = new HashMap<>();
        for (String fieldName : solrDocument.getFieldNames()) {
            solrDocumentFieldValueMap.put(fieldName, solrDocument.getFieldValue(fieldName));
        }
        if ((solrDocumentFieldValueMap.containsKey(KYLO_COLLECTION)) && (solrDocumentFieldValueMap.get(KYLO_COLLECTION).toString().equals(KYLO_DATA))) {
            searchResultData.add(getTableSearchResultData(solrDocumentFieldValueMap, solrResponse));
        } else // collection creator needs to set up the collection to have an additional field called 'kylo_collection' that is set to the collection's name
        if (Objects.equals(solrDocumentFieldValueMap.get(KYLO_COLLECTION), SearchIndex.DATASOURCES)) {
            searchResultData.add(getSchemaSearchResultData(solrDocumentFieldValueMap, solrResponse));
        } else {
            searchResultData.add(getUnknownTypeSearchResultData(solrDocumentFieldValueMap));
        }
    }
    SearchResult solrSearchResult = new SearchResult();
    solrSearchResult.setQuery(query);
    solrSearchResult.setTotalHits(solrResponse.getResults().getNumFound());
    solrSearchResult.setFrom((long) (start + 1));
    solrSearchResult.setTo((long) (start + size));
    if (solrResponse.getResults().getNumFound() == 0) {
        solrSearchResult.setFrom(0L);
    }
    if (solrResponse.getResults().getNumFound() < (start + size)) {
        solrSearchResult.setTo(solrResponse.getResults().getNumFound());
    }
    solrSearchResult.setTookInMillis((long) solrResponse.getQTime());
    solrSearchResult.setEngine(SOLR);
    solrSearchResult.setSearchResults(searchResultData);
    solrSearchResult.setSearchResultsSummary(getSearchResultSummary());
    return solrSearchResult;
}
Also used : TableSearchResultData(com.thinkbiganalytics.search.rest.model.TableSearchResultData) SchemaSearchResultData(com.thinkbiganalytics.search.rest.model.SchemaSearchResultData) SearchResultData(com.thinkbiganalytics.search.rest.model.SearchResultData) UnknownTypeSearchResultData(com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData) SolrDocument(org.apache.solr.common.SolrDocument) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult)

Aggregations

SchemaSearchResultData (com.thinkbiganalytics.search.rest.model.SchemaSearchResultData)3 SearchResult (com.thinkbiganalytics.search.rest.model.SearchResult)3 SearchResultData (com.thinkbiganalytics.search.rest.model.SearchResultData)3 TableSearchResultData (com.thinkbiganalytics.search.rest.model.TableSearchResultData)3 UnknownTypeSearchResultData (com.thinkbiganalytics.search.rest.model.UnknownTypeSearchResultData)3 ArrayList (java.util.ArrayList)3 CategoryMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData)2 FeedMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData)2 ElasticSearchRestSearchHit (com.thinkbiganalytics.search.rest.model.es.ElasticSearchRestSearchHit)1 HashMap (java.util.HashMap)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SearchHit (org.elasticsearch.search.SearchHit)1