本文整理汇总了Java中io.searchbox.core.SearchResult.Hit方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.Hit方法的具体用法?Java SearchResult.Hit怎么用?Java SearchResult.Hit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.searchbox.core.SearchResult
的用法示例。
在下文中一共展示了SearchResult.Hit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapResults
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
public <T> AggregatedPage<T> mapResults(SearchResult response, Class<T> clazz, List<AbstractAggregationBuilder> aggregations, Pageable pageable) {
LinkedList<T> results = new LinkedList<>();
for (SearchResult.Hit<JsonObject, Void> hit : response.getHits(JsonObject.class)) {
if (hit != null) {
results.add(mapSource(hit.source, clazz));
}
}
String scrollId = null;
if (response instanceof ExtendedSearchResult) {
scrollId = ((ExtendedSearchResult) response).getScrollId();
}
return new AggregatedPageImpl<>(results, pageable, response.getTotal(), response.getAggregations(), scrollId);
}
示例2: mapResults
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
public <T> AggregatedPage<T> mapResults(SearchResult response, Class<T> clazz, Pageable pageable) {
String scrollId = ((ExtendedSearchResult) response).getScrollId();
List<T> result = new ArrayList<>();
for (SearchResult.Hit<T, Void> searchHit : response.getHits(clazz)) {
if (response.getHits(clazz).size() <= 0) {
return new AggregatedPageImpl<>(Collections.emptyList(), scrollId);
}
result.add(searchHit.source);
}
if (result.size() > 0) {
return new AggregatedPageImpl<>(result, scrollId);
}
return new AggregatedPageImpl<>(Collections.emptyList(), scrollId);
}
示例3: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Habit> doInBackground(String... user_ids) {
verifySettings();
if(user_ids.length > 1){
throw new RuntimeException("Only one User ID is expected for task.");
}
ArrayList<Habit> habitsResult = new ArrayList<Habit>();
String query = "{\n" +
" \"query\": {\n" +
" \"query_string\" : {\n" +
" \"default_field\" : \"associatedUserID\",\n" +
" \"query\" : \"" + user_ids[0] + "\"\n" +
" }\n" +
" }\n" +
" }";
Search search = new Search.Builder(query)
.addIndex(INDEX_NAME)
.addType("habit")
.build();
try{
SearchResult result = client.execute(search);
if(result.isSucceeded()) {
for(SearchResult.Hit x: result.getHits(Habit.class)){
Habit retrievedHabit = (Habit)x.source;
retrievedHabit.setHabitID(x.id);
habitsResult.add(retrievedHabit);
}
}
} catch (IOException e){
Log.i("Error", "Something went wrong when we tried to communicate with the elastic search server!");
}
return habitsResult;
}
示例4: searchObj
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
public <T> WSearchResult<T> searchObj(String index, String type, SearchQuery query, Class<T> cls) throws
Exception {
Search.Builder builder = new Search.Builder(convert.toText(query));
if (index != null) {
builder.addIndex(index);
}
if (type != null) {
builder.addType(type);
}
SearchResult result = _exec(builder.build());
if (result != null) {
WSearchResult<T> wresult = new WSearchResult<>();
WSearchResultHits<T> hits = new WSearchResultHits<>();
hits.setTotal(result.getTotal());
List<SearchResult.Hit<T, Void>> allHist = result.getHits(cls);
List<WEsDoc<T>> data = new ArrayList<>();
for (SearchResult.Hit<T, Void> hit : allHist) {
WEsDoc<T> doc = new WEsDoc<>();
doc.setIndex(hit.index);
doc.setType(hit.type);
doc.setIndex(hit.index);
doc.setSource(hit.source);
doc.setScore(hit.score);
data.add(doc);
}
hits.setHits(data);
wresult.setHits(hits);
return wresult;
}
return null;
}
示例5: getIDs
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
private List<Serializable> getIDs(SearchResult result) {
List<Serializable> contents = new ArrayList<>();
if (result != null) {
List<SearchResult.Hit<Content, Void>> hits = result.getHits(Content.class);
contents = hits.stream()
.map(hit -> hit.source.getId())
.collect(Collectors.toList());
}
return contents;
}
示例6: extractHighlightedContent
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
* Extracts highlighted content from a given {@link SearchHit}
*
* @param searchHit a given {@link SearchHit} from the elasticsearch results
* @param preTag the specified pre-tag for highlighting
* @param postTag the specified post-tag for highlighting
*
* @return {@link Highlight} a cleaned highlighted content
*/
private Highlight extractHighlightedContent(SearchResult.Hit<Map, Void> searchHit, String preTag, String postTag)
{
Highlight highlightedContent = new Highlight();
List<Field> highlightFields = new ArrayList<>();
// make sure there is highlighted content in the search hit
if (MapUtils.isNotEmpty(searchHit.highlight))
{
Set<String> keySet = searchHit.highlight.keySet();
for (String key : keySet)
{
Field field = new Field();
// Extract the field-name
field.setFieldName(key);
List<String> cleanFragments = new ArrayList<>();
// Extract fragments which have the highlighted content
List<String> fragments = searchHit.highlight.get(key);
for (String fragment : fragments)
{
cleanFragments.add(HerdStringUtils.stripHtml(fragment, preTag, postTag));
}
field.setFragments(cleanFragments);
highlightFields.add(field);
}
}
highlightedContent.setFields(highlightFields);
return highlightedContent;
}
示例7: findTicksByRic
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
public List<TickJson> findTicksByRic(String ticker) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchQuery("ticker", ticker));
Search search = new Search.Builder(searchSourceBuilder.toString())
.addIndex(infrastructureProperties.getElasticsearchIndexForTicks())
.addType(infrastructureProperties.getElasticsearchTypeForTicks())
.build();
System.out.println(search.toString());
SearchResult result = null;
try {
result = elasticsearch.execute(search);
} catch (IOException e) {
logger.error("getAllTicks() could not execute query on elasticsearch: {}, [{}]",
e.getMessage(), search.toString());
}
// List<SearchResult.Hit<Article, Void>> hits = searchResult.getHits(Article.class);
// @SuppressWarnings({ "unused", "deprecation" })
// List<String> articles = result.getSourceAsObjectList(String.class);
// @SuppressWarnings("unused")
// Map json = result.getJsonMap();
List<SearchResult.Hit<TickPojo, Void>> hits = result.getHits(TickPojo.class);
for (Hit<TickPojo, Void> hit : hits) {
TickPojo tick = hit.source;
logger.info(tick.toString());
}
// List<SearchResult.Hit<TickJson, Void>> hits = result.getHits(TickJson.class);
logger.info(result.toString());
return null;
}
示例8: getRawHistory
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
private List<Object[]> getRawHistory(Long id, Long min, Long max) {
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// searchSourceBuilder.query(boolQuery()
// .must(termQuery("id", id))
// .must(rangeQuery("timestamp").from(min).to(max)))
// .sort("timestamp", SortOrder.ASC)
// .size(1000);
// String query = searchSourceBuilder.toString();
String query = String.format("{\n" +
" \"size\" : 1000,\n" +
" \"query\" : {\n" +
" \"bool\" : {\n" +
" \"must\" : [ {\n" +
" \"term\" : {\n" +
" \"id\" : %d\n" +
" }\n" +
" }, {\n" +
" \"range\" : {\n" +
" \"timestamp\" : {\n" +
" \"from\" : %d,\n" +
" \"to\" : %d,\n" +
" \"include_lower\" : true,\n" +
" \"include_upper\" : true\n" +
" }\n" +
" }\n" +
" } ]\n" +
" }\n" +
" },\n" +
" \"sort\" : [ {\n" +
" \"timestamp\" : {\n" +
" \"order\" : \"asc\"\n" +
" }\n" +
" } ]\n" +
"}", id, min, max);
Search search = new Search.Builder(query).addIndex(timeSeriesIndex).build();
try {
SearchResult result = client.execute(search);
List<Object[]> results = new ArrayList<>();
for (SearchResult.Hit<Map, Void> hit : result.getHits(Map.class)) {
results.add(new Object[]{hit.source.get("timestamp"), hit.source.get("value")});
}
return results;
} catch (IOException e) {
throw new RuntimeException("Error querying raw tag history", e);
}
}