当前位置: 首页>>代码示例>>Java>>正文


Java SearchResult.getHits方法代码示例

本文整理汇总了Java中io.searchbox.core.SearchResult.getHits方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getHits方法的具体用法?Java SearchResult.getHits怎么用?Java SearchResult.getHits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.searchbox.core.SearchResult的用法示例。


在下文中一共展示了SearchResult.getHits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: elasticSearch

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
private static void elasticSearch(JestClient client, String indexName, String type, String query) {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query);
	searchSourceBuilder.query(queryStringQueryBuilder);
	Search searchElastic = (Search) new Search.Builder(searchSourceBuilder.toString())
			// multiple index or types can be added.
			.addIndex(indexName).addType(type).build();

	try {
		SearchResult elasticRs = client.execute(searchElastic);

		List<Hit<Article, Void>> hits = elasticRs.getHits(Article.class);
		for (Hit<Article, Void> hit : hits) {
			Article talk = hit.source;
			System.out.println("Elastic hits: " + talk.toString());
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:21,代码来源:ElasticApp.java

示例2: jestSearchModel

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
private static void jestSearchModel(JestClient client, String indexName, String type, String query) {
	Search.Builder searchBuilder = new Search.Builder(query).addIndex(indexName).addType(type);
	try {
		SearchResult result = client.execute(searchBuilder.build());

		System.out.println(result.getJsonObject());

		List<Hit<Article, Void>> hits = result.getHits(Article.class);
		for (Hit<Article, Void> hit : hits) {
			Article talk = hit.source;
			System.out.println("JEST Search model hit: " + talk.toString());
		}

	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:18,代码来源:ElasticApp.java

示例3: 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);
	}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:18,代码来源:DefaultJestResultsMapper.java

示例4: 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);
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:17,代码来源:JestElasticsearchTemplateTests.java

示例5: testQuery

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Test
@Ignore
public void testQuery() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    FilterBuilder filter = FilterBuilders.boolFilter()
            .must(FilterBuilders.termFilter("attributes.league", "Flashback Event HC (IC002)"))
            .must(FilterBuilders.termFilter("attributes.equipType", "Jewel"))
            .must(FilterBuilders.rangeFilter("modsTotal.#% increased maximum Life").gt(4))
            .must(FilterBuilders.termFilter("shop.verified", "yes"))
           // .must(FilterBuilders.termFilter("attributes.rarity", "Magic"))
            ;

    searchSourceBuilder
            .query(QueryBuilders.filteredQuery(QueryBuilders.boolQuery().minimumNumberShouldMatch(2)
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Area Damage"))
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Projectile Damage"))
                    .should(QueryBuilders.rangeQuery("modsTotal.#% increased Chaos Damage")), filter))
            .sort("_score");
    SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
	hits.stream().map(hit -> hit.source).forEach(System.out::println);
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:23,代码来源:ExileToolsSearchClientTest.java

示例6: testExecuteMjolnerUsingFilters

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
	 * As per ES documentation/tome, the best way to do our search is via Filters
	 */
	@Test
	@Ignore
	public void testExecuteMjolnerUsingFilters() throws Exception {
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		List<FilterBuilder> filters = new LinkedList<>();
		
		filters.add(FilterBuilders.termFilter("attributes.league", "Flashback Event (IC001)"));
//		filters.add(FilterBuilders.termFilter("info.name", "Mjolner"));
		filters.add(FilterBuilders.termFilter("info.name", "Hegemony's Era"));
		filters.add(FilterBuilders.rangeFilter("properties.Weapon.Physical DPS").from(400));
		
		FilterBuilder filter = FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()]));
		searchSourceBuilder.query(QueryBuilders.filteredQuery(null, filter));
		searchSourceBuilder.size(100);
		SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
		List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
		for (Hit<ExileToolsHit, Void> hit : hits) {
//			logger.info(hit.source.toString());
//			hit.source.getQuality().ifPresent( q -> logger.info(q.toString()) );
			hit.source.getPhysicalDPS().ifPresent( q -> logger.info(q.toString()) );
//			logger.info(hit.source.toString());
//			logger.info(hit.source.getRequirements().getLevel().toString());
//			logger.info(hit.source.getExplicitMods().toString());
		}
	}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:29,代码来源:ExileToolsSearchClientTest.java

示例7: testShops

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Test
@Ignore
public void testShops() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	searchSourceBuilder.query(QueryBuilders.boolQuery()
			.must(QueryBuilders.matchQuery("attributes.league", "Flashback Event (IC001)"))
			.mustNot(QueryBuilders.matchQuery("attributes.league", "Flashback Event (IC001)")
					));
	searchSourceBuilder.size(1);
	
	SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
	for (Hit<ExileToolsHit, Void> hit : hits) {
		logger.info(hit.source.toString());
	}
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:17,代码来源:ExileToolsSearchClientTest.java

示例8: fetch

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void fetch() throws StorageException {
    try {
        Builder builder = new SearchScroll.Builder(scrollId, "1m")
                .setParameter(Parameters.SIZE, 1);
        SearchScroll scroll = new SearchScroll(builder) {
            @Override
            public JestResult createNewElasticSearchResult(String responseBody, int statusCode,
                    String reasonPhrase, Gson gson) {
                return createNewElasticSearchResult(new SearchResult(gson), responseBody, statusCode, reasonPhrase, gson);
            }
        };
        SearchResult response = (SearchResult) esClient.execute(scroll);
        this.hits = (List) response.getHits(Map.class);
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:19,代码来源:EsStorage.java

示例9: 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;
}
 
开发者ID:CMPUT301F17T23,项目名称:routineKeen,代码行数:38,代码来源:ElasticSearchController.java

示例10: 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;
}
 
开发者ID:DataSays,项目名称:wES,代码行数:33,代码来源:JestClient.java

示例11: 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;
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:13,代码来源:ElasticsearchSearcher.java

示例12: main

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {

		 // Construct a new Jest client according to configuration via factory
		 JestClientFactory factory = new JestClientFactory();
		 factory.setHttpClientConfig(new HttpClientConfig
		                        .Builder("http://api.exiletools.com/index")
		                        .multiThreaded(true)
		                        .build());
		 JestHttpClient client = (JestHttpClient) factory.getObject();
		 
		 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//		 searchSourceBuilder.query(QueryBuilders.matchQuery("info.name", "Tabula Rasa"));
		 searchSourceBuilder.query(QueryBuilders.matchQuery("info.name", "Mjolner"));
		 searchSourceBuilder.size(1);

		 System.out.println(searchSourceBuilder.toString());

		 ExileToolsSearchAction search = new ExileToolsSearchAction.Builder(searchSourceBuilder.toString())
		                                 .setHeader("Authorization", "DEVELOPMENT-Indexer")
		                                 .build();
		 
		 SearchResult result = client.execute(search);
		 
		 System.out.println(result.getPathToResult());
		 System.out.println(result.getJsonString());
		 
		 List<Hit<ExileToolsHit, Void>> articles = result.getHits(ExileToolsHit.class);
		 System.out.println(articles);
		 articles.stream().forEach( (e) -> {
			 System.out.println(e.source.getMd5sum());
			 System.out.println(e.source.getInfo());
			 System.out.println(e.source.getAttributes());
			 System.out.println(e.source.getShop());
			 System.out.println(e.source.getSockets());
		 } );
		 client.shutdownClient();
	}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:42,代码来源:Main.java

示例13: testExecuteMjolner

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Test
@Ignore
public void testExecuteMjolner() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	 searchSourceBuilder.query(QueryBuilders.matchQuery("info.name", "Mjolner"));
	 searchSourceBuilder.size(1);
	
	SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
	for (Hit<ExileToolsHit, Void> hit : hits) {
		logger.info(hit.source.toString());
	}
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:14,代码来源:ExileToolsSearchClientTest.java

示例14: testExecuteTabula

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Test
@Ignore
public void testExecuteTabula() throws Exception {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	searchSourceBuilder.query(QueryBuilders.matchQuery("info.name", "Tabula Rasa"));
	searchSourceBuilder.size(1);
	
	SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
	List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
	for (Hit<ExileToolsHit, Void> hit : hits) {
		logger.info(hit.source.toString());
	}
}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:14,代码来源:ExileToolsSearchClientTest.java

示例15: testGetLeagues

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Test
	@Ignore
	public void testGetLeagues() throws Exception {
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.aggregation(AggregationBuilders
				.terms("leagues")
				.field("attributes.league"));
//		searchSourceBuilder.size(0);
		
		SearchResult result = client.execute(searchSourceBuilder.toString()).getSearchResult();
		List<Hit<ExileToolsHit, Void>> hits = result.getHits(ExileToolsHit.class);
		for (Hit<ExileToolsHit, Void> hit : hits) {
			logger.info(hit.source.toString());
		}
	}
 
开发者ID:thirdy,项目名称:blackmarket,代码行数:16,代码来源:ExileToolsSearchClientTest.java


注:本文中的io.searchbox.core.SearchResult.getHits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。