Search in sources :

Example 1 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 2 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 3 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)

Example 4 with SearchResult

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

the class SearchRestController method search.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation("Queries a search engine.")
@ApiResponses({ @ApiResponse(code = 200, message = "The search results.", response = SearchResult.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "The search engine is unavailable.", response = RestResponseStatus.class) })
@Nonnull
public Response search(@QueryParam("q") String query, @QueryParam("rows") @DefaultValue("20") Integer rows, @QueryParam("start") @DefaultValue("0") Integer start) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_GLOBAL_SEARCH);
    if (searchEngine != null) {
        final SearchResult result = searchEngine.search(query, rows, start);
        return Response.ok(result).build();
    } else {
        RestResponseStatus.ResponseStatusBuilder builder = new RestResponseStatus.ResponseStatusBuilder();
        builder.message("Search functionality is not available since no search engine is configured.");
        return Response.accepted(builder.buildError()).status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : SearchResult(com.thinkbiganalytics.search.rest.model.SearchResult) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Produces(javax.ws.rs.Produces) Nonnull(javax.annotation.Nonnull) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with SearchResult

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

the class SearchFeedMetadataEsIT method verifySearchResultOnUserProperties2.

private void verifySearchResultOnUserProperties2(String term) {
    Response response = given(SearchRestController.BASE).when().get("/?q=" + term);
    response.then().statusCode(HTTP_OK);
    SearchResult searchResult = response.as(SearchResult.class);
    Assert.assertEquals("0", searchResult.getTotalHits().toString());
}
Also used : Response(com.jayway.restassured.response.Response) 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