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