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;
}
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;
}
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;
}
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();
}
}
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());
}
Aggregations