Search in sources :

Example 11 with SearchResult

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

the class SearchFeedMetadataEsIT method enableMetadataIndexingForFeedAndThenSearchAgain.

private void enableMetadataIndexingForFeedAndThenSearchAgain(String feedId) {
    Response response = getFeedById(feedId);
    FeedMetadata feedMetadata = response.as(FeedMetadata.class);
    Assert.assertFalse(feedMetadata.isAllowIndexing());
    feedMetadata.setAllowIndexing(true);
    createFeed(feedMetadata);
    String term = "Bb2000y";
    Response searchReponse = given(SearchRestController.BASE).when().get("/?q=" + term);
    searchReponse.then().statusCode(HTTP_OK);
    SearchResult searchResult = searchReponse.as(SearchResult.class);
    Assert.assertEquals("1", searchResult.getTotalHits().toString());
    Assert.assertEquals("KYLO_FEEDS", searchResult.getSearchResults().get(0).getType().toString());
    Assert.assertEquals("pk10A common=Aa1000x\tpv20B utility=Bb2000y S99\tor30 organization=Corporate Z5000", ((FeedMetadataSearchResultData) searchResult.getSearchResults().get(0)).getUserProperties());
    Assert.assertEquals(1, searchResult.getSearchResults().get(0).getHighlights().size());
    Assert.assertEquals("User properties", searchResult.getSearchResults().get(0).getHighlights().get(0).getKey());
    String expected = "<table style='border:1px solid black; border-collapse: collapse;'>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'><font style='font-style:italic'>name</font></td>\n" + "<td style='border:1px solid black;padding: 3px;'><font style='font-style:italic'>value</font></td>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "pk10A common</td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "Aa1000x</td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "pv20B utility</td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "<font style='font-weight:bold'>Bb2000y</font> S99</td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "or30 organization</td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "Corporate Z5000</td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "</table>";
    Assert.assertEquals(expected, searchResult.getSearchResults().get(0).getHighlights().get(0).getValue());
}
Also used : Response(com.jayway.restassured.response.Response) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult)

Example 12 with SearchResult

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

the class SearchFeedMetadataEsIT method verifySearchResultOnUserProperties3.

private void verifySearchResultOnUserProperties3(String term) {
    Response response = given(SearchRestController.BASE).when().get("/?q=" + term);
    response.then().statusCode(HTTP_OK);
    SearchResult searchResult = response.as(SearchResult.class);
    Assert.assertEquals("1", searchResult.getTotalHits().toString());
    Assert.assertEquals("User properties", searchResult.getSearchResults().get(0).getHighlights().get(0).getKey());
    String expected = "<table style='border:1px solid black; border-collapse: collapse;'>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'><font style='font-style:italic'>name</font></td>\n" + "<td style='border:1px solid black;padding: 3px;'><font style='font-style:italic'>value</font></td>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "pk10A common</td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "Aa1000x</td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "<font style='font-weight:bold'>or30</font> <font style='font-weight:bold'>organization</font></td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "<font style='font-weight:bold'>Corporate</font> <font style='font-weight:bold'>Z5000</font></td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "<tr>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "pv20B utility</td style='border:1px solid black;padding: 3px;'>\n" + "<td style='border:1px solid black;padding: 3px;'>\n" + "Bb2000y S99</td style='border:1px solid black;padding: 3px;'>\n" + "</tr>\n" + "</table>";
    Assert.assertEquals(expected, searchResult.getSearchResults().get(0).getHighlights().get(0).getValue());
}
Also used : Response(com.jayway.restassured.response.Response) SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult)

Example 13 with SearchResult

use of com.thinkbiganalytics.search.rest.model.SearchResult 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 14 with SearchResult

use of com.thinkbiganalytics.search.rest.model.SearchResult 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 15 with SearchResult

use of com.thinkbiganalytics.search.rest.model.SearchResult 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

SearchResult (com.thinkbiganalytics.search.rest.model.SearchResult)30 Response (com.jayway.restassured.response.Response)26 SchemaSearchResultData (com.thinkbiganalytics.search.rest.model.SchemaSearchResultData)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 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)2 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)2 CategoryMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.CategoryMetadataSearchResultData)2 FeedMetadataSearchResultData (com.thinkbiganalytics.search.rest.model.FeedMetadataSearchResultData)2 RestResponseStatus (com.thinkbiganalytics.rest.model.RestResponseStatus)1 ElasticSearchRestSearchHit (com.thinkbiganalytics.search.rest.model.es.ElasticSearchRestSearchHit)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 SolrDocument (org.apache.solr.common.SolrDocument)1