本文整理汇总了Java中org.springframework.data.solr.core.query.result.FacetPage类的典型用法代码示例。如果您正苦于以下问题:Java FacetPage类的具体用法?Java FacetPage怎么用?Java FacetPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FacetPage类属于org.springframework.data.solr.core.query.result包,在下文中一共展示了FacetPage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: queryForFacetPage
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Override
public <T> FacetPage<T> queryForFacetPage(FacetQuery query, Class<T> clazz) {
Assert.notNull(query, "Query must not be 'null'.");
Assert.notNull(clazz, "Target class must not be 'null'.");
QueryResponse response = query(query);
List<T> beans = convertQueryResponseToBeans(response, clazz);
SolrDocumentList results = response.getResults();
SolrResultPage<T> page = new SolrResultPage<T>(beans, query.getPageRequest(), results.getNumFound(),
results.getMaxScore());
page.addAllFacetFieldResultPages(ResultHelper.convertFacetQueryResponseToFacetPageMap(query, response));
page.addAllFacetPivotFieldResult(ResultHelper.convertFacetQueryResponseToFacetPivotMap(query, response));
page.setFacetQueryResultPage(ResultHelper.convertFacetQueryResponseToFacetQueryResult(query, response));
return page;
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:18,代码来源:SolrTemplate.java
示例2: testFacetQueryWithFacetPrefix
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetQueryWithFacetPrefix() {
ExampleSolrBean season = new ExampleSolrBean("1", "spring", "season");
ExampleSolrBean framework = new ExampleSolrBean("2", "spring", "framework");
ExampleSolrBean island = new ExampleSolrBean("3", "java", "island");
ExampleSolrBean language = new ExampleSolrBean("4", "java", "language");
solrTemplate.saveBeans(Arrays.asList(season, framework, island, language));
solrTemplate.commit();
FacetQuery q = new SimpleFacetQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
.setFacetOptions(new FacetOptions().addFacetOnField("name").setFacetLimit(5).setFacetPrefix("spr"));
FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);
Page<FacetFieldEntry> facetPage = page.getFacetResultPage(new SimpleField("name"));
for (FacetFieldEntry entry : facetPage) {
Assert.assertEquals("spring", entry.getValue());
Assert.assertEquals("name", entry.getField().getName());
Assert.assertEquals(2l, entry.getValueCount());
}
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:22,代码来源:ITestSolrTemplate.java
示例3: findByNameAndFacetOnCategories
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void findByNameAndFacetOnCategories() {
FacetPage<Book> booksFacetPage = bookRepository.findByNameAndFacetOnCategories("Island", new PageRequest(0, 2));
// There are 4 books which contain "Island" in their name. However, only the first 2 books are returned because
// a page with size 2 is requested. The next two books could be requested using "new PageRequest(1, 2)"
assertEquals(2, booksFacetPage.getNumberOfElements());
// 3 of these 4 books are categorized as Adventure
// 2 of these 4 books are categorized as Humor
// 1 of these 4 books is categorized as Romance
Map<Category, Long> categoryFacetCounts = getCategoryFacetCounts(booksFacetPage);
assertEquals(new Long(3), categoryFacetCounts.get(ADVENTURE));
assertEquals(new Long(2), categoryFacetCounts.get(HUMOR));
assertEquals(new Long(1), categoryFacetCounts.get(ROMANCE));
}
开发者ID:mscharhag,项目名称:Spring-data-solr-example,代码行数:18,代码来源:BookRepositoryTests.java
示例4: productCategories
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@RequestMapping(value = "/products/categories", method = RequestMethod.GET)
public String productCategories(Model model) {
FacetPage<Product> catfacetPage = productService.getFacetedProductsCategory();
Page<FacetFieldEntry> catPage = catfacetPage.getFacetResultPage(Product.CATEGORY_FIELD);
List<ProductCategory> results = new ArrayList<ProductCategory>();
for (FacetFieldEntry entry : catPage) {
results.add(new ProductCategory(entry.getValue(), toIntExact(entry.getValueCount())));
}
model.addAttribute(MODEL_ATTRIBUTE_PRODUCT_CATEGORIES, results);
return PRODUCT_CATEGORIES_VIEW;
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:15,代码来源:SolrController.java
示例5: autoComplete
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@ResponseBody
@RequestMapping(value = "/products/autocomplete", produces = "application/json")
public Set<String> autoComplete(Model model, @RequestParam("term") String query) {
if (StringUtils.isBlank(query)) {
return Collections.emptySet();
}
PageRequest pageRequest = new PageRequest(0, 1);
FacetPage<Product> result = productService.autocompleteNameFragment(query, pageRequest);
Set<String> titles = new LinkedHashSet<String>();
for (Page<FacetFieldEntry> page : result.getFacetResultPages()) {
for (FacetFieldEntry entry : page) {
if (entry.getValue().contains(query)) {
titles.add(entry.getValue());
}
}
}
// To display complete Product Name field in dropdown ----------------------------------- */
//
// List<Product> result = productService.getProductsByStartOfName(query);
//
// Set<String> titles = new LinkedHashSet<String>();
// for (Product product : result) {
// if (product.getName().toLowerCase().contains(query.toLowerCase())) {
// titles.add(product.getName());
// }
// }
return titles;
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:33,代码来源:SolrController.java
示例6: findByFacetOnAvailable
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Override
public FacetPage<Product> findByFacetOnAvailable(Pageable pageable) {
FacetQuery query = new SimpleFacetQuery(new
Criteria(IProduct.DOCTYPE_FIELD).is(SolrDocType.PRODUCT));
query.setFacetOptions(new FacetOptions(Product.AVAILABLE_FIELD).setFacetLimit(5));
query.setPageRequest(new PageRequest(0, 100));
return getSolrOperations().queryForFacetPage(query, Product.class);
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:10,代码来源:SimpleProductRepositoryImpl.java
示例7: findByFacetOnCategory
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Override
public FacetPage<Product> findByFacetOnCategory(Pageable pageable) {
FacetQuery query = new
SimpleFacetQuery(new Criteria(IProduct.DOCTYPE_FIELD)
.is(SolrDocType.PRODUCT));
query.setFacetOptions(new FacetOptions(Product.CATEGORY_FIELD)
.setPageable(new PageRequest(0,20)));
return getSolrOperations().queryForFacetPage(query, Product.class);
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:13,代码来源:SimpleProductRepositoryImpl.java
示例8: autocompleteNameFragment
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Override
public FacetPage<Product> autocompleteNameFragment(String fragment, Pageable pageable) {
if (StringUtils.isBlank(fragment)) {
return new SolrResultPage<Product>(Collections.<Product> emptyList());
}
return customProductRepository.findByNameStartingWith(splitSearchTermAndRemoveIgnoredCharacters(fragment), pageable);
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:8,代码来源:ProductServiceImpl.java
示例9: testFacetQuery
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetQuery() {
FacetPage<Product> facetPage = repo.findProductCategoryFacets(new PageRequest(0, 100));
Assert.assertEquals(repo.findAllProducts().size(), facetPage.getNumberOfElements());
Page<FacetFieldEntry> page = facetPage.getFacetResultPage(SolrProductField.CATEGORY);
Assert.assertEquals(INITIAL_CATEGORY_COUNT, page.getNumberOfElements());
for (FacetFieldEntry entry : page) {
Assert.assertEquals(SolrProductField.CATEGORY.getName(), entry.getField().getName());
Assert.assertEquals(repo.findByCategory(entry.getValue()).size(), entry.getValueCount());
}
}
开发者ID:mintster,项目名称:nixmash-blog,代码行数:15,代码来源:SolrProductTests.java
示例10: executeFind
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Override
protected FacetPage<?> executeFind(Query query) {
Assert.isInstanceOf(FacetQuery.class, query);
EntityMetadata<?> metadata = solrQueryMethod.getEntityInformation();
return solrOperations.queryForFacetPage((FacetQuery) query, metadata.getJavaType());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:8,代码来源:AbstractSolrQuery.java
示例11: testFacetOnSingleField
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetOnSingleField() {
FacetPage<ProductBean> facetPage = repo.findAllFacetOnPopularity(new PageRequest(0, 10));
Assert.assertEquals(1, facetPage.getFacetFields().size());
Page<FacetFieldEntry> page = facetPage.getFacetResultPage(facetPage.getFacetFields().iterator().next());
Assert.assertEquals(3, page.getContent().size());
for (FacetFieldEntry entry : page) {
Assert.assertEquals("popularity", entry.getField().getName());
}
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:11,代码来源:ITestSolrRepositoryOperations.java
示例12: testFacetOnSingleQuery
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetOnSingleQuery() {
FacetPage<ProductBean> facetPage = repo.findAllFacetQueryPopularity(new PageRequest(0, 10));
Assert.assertEquals(0, facetPage.getFacetFields().size());
Page<FacetQueryEntry> facets = facetPage.getFacetQueryResult();
Assert.assertEquals(1, facets.getContent().size());
Assert.assertEquals("popularity:[* TO 3]", facets.getContent().get(0).getValue());
Assert.assertEquals(3, facets.getContent().get(0).getValueCount());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:10,代码来源:ITestSolrRepositoryOperations.java
示例13: testFacetWithParametrizedQuery
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetWithParametrizedQuery() {
FacetPage<ProductBean> facetPage = repo.findAllFacetQueryPopularity(3, new PageRequest(0, 10));
Assert.assertEquals(0, facetPage.getFacetFields().size());
Page<FacetQueryEntry> facets = facetPage.getFacetQueryResult();
Assert.assertEquals(1, facets.getContent().size());
Assert.assertEquals("popularity:[* TO 3]", facets.getContent().get(0).getValue());
Assert.assertEquals(3, facets.getContent().get(0).getValueCount());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:10,代码来源:ITestSolrRepositoryOperations.java
示例14: testFacetOnMulipleQueries
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetOnMulipleQueries() {
FacetPage<ProductBean> facetPage = repo.findAllFacetQueryAvailableTrueAndAvailableFalse(new PageRequest(0, 10));
Assert.assertEquals(0, facetPage.getFacetFields().size());
Page<FacetQueryEntry> facets = facetPage.getFacetQueryResult();
Assert.assertEquals(2, facets.getContent().size());
Assert.assertEquals("inStock:true", facets.getContent().get(0).getValue());
Assert.assertEquals(3, facets.getContent().get(0).getValueCount());
Assert.assertEquals("inStock:false", facets.getContent().get(1).getValue());
Assert.assertEquals(1, facets.getContent().get(1).getValueCount());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:12,代码来源:ITestSolrRepositoryOperations.java
示例15: testFacetWithStaticPrefix
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetWithStaticPrefix() {
FacetPage<ProductBean> facetPage = repo.findAllFacetOnNameWithStaticPrefix(new PageRequest(0, 10));
Assert.assertEquals(1, facetPage.getFacetFields().size());
Page<FacetFieldEntry> page = facetPage.getFacetResultPage("name");
Assert.assertEquals(1, page.getContent().size());
Assert.assertEquals("name", page.getContent().get(0).getField().getName());
Assert.assertEquals("product", page.getContent().get(0).getValue());
Assert.assertEquals(1, page.getContent().get(0).getValueCount());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:12,代码来源:ITestSolrRepositoryOperations.java
示例16: testFacetWithDynamicPrefix
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetWithDynamicPrefix() {
FacetPage<ProductBean> facetPage = repo.findAllFacetOnNameWithDynamicPrefix("pro", new PageRequest(0, 10));
Assert.assertEquals(1, facetPage.getFacetFields().size());
Page<FacetFieldEntry> page = facetPage.getFacetResultPage("name");
Assert.assertEquals(1, page.getContent().size());
Assert.assertEquals("name", page.getContent().get(0).getField().getName());
Assert.assertEquals("product", page.getContent().get(0).getValue());
Assert.assertEquals(1, page.getContent().get(0).getValueCount());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:12,代码来源:ITestSolrRepositoryOperations.java
示例17: testFacetQueryWithPivotFields
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetQueryWithPivotFields() {
List<ExampleSolrBean> values = new ArrayList<ExampleSolrBean>();
for (int i = 0; i < 10; i++) {
values.add(createExampleBeanWithId(Integer.toString(i)));
}
solrTemplate.saveBeans(values);
solrTemplate.commit();
FacetQuery q = new SimpleFacetQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
.setFacetOptions(new FacetOptions().addFacetOnPivot("cat", "name"));
FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);
List<FacetPivotFieldEntry> pivotEntries = page.getPivot("cat,name");
Assert.assertNotNull(pivotEntries);
Assert.assertEquals(10, pivotEntries.size());
for (FacetPivotFieldEntry entry1 : pivotEntries) {
Assert.assertNotNull(entry1.getValue());
Assert.assertEquals("cat", entry1.getField().getName());
Assert.assertEquals(1l, entry1.getValueCount());
for (FacetPivotFieldEntry entry2 : entry1.getPivot()) {
Assert.assertNotNull(entry2.getValue());
Assert.assertEquals("name", entry2.getField().getName());
Assert.assertEquals(1l, entry2.getValueCount());
}
}
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:31,代码来源:ITestSolrTemplate.java
示例18: testFacetQueryWithFacetQueries
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
@Test
public void testFacetQueryWithFacetQueries() {
List<ExampleSolrBean> values = new ArrayList<ExampleSolrBean>();
for (int i = 0; i < 10; i++) {
ExampleSolrBean bean = createExampleBeanWithId(Integer.toString(i));
bean.setInStock(i % 2 == 0);
values.add(bean);
}
solrTemplate.saveBeans(values);
solrTemplate.commit();
FacetQuery q = new SimpleFacetQuery(new SimpleStringCriteria("*:*"));
q.setFacetOptions(new FacetOptions(new SimpleQuery(new SimpleStringCriteria("inStock:true")), new SimpleQuery(
new SimpleStringCriteria("inStock:false"))));
FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);
Page<FacetQueryEntry> facetQueryResultPage = page.getFacetQueryResult();
Assert.assertEquals(2, facetQueryResultPage.getContent().size());
Assert.assertEquals("inStock:true", facetQueryResultPage.getContent().get(0).getValue());
Assert.assertEquals(5, facetQueryResultPage.getContent().get(0).getValueCount());
Assert.assertEquals("inStock:false", facetQueryResultPage.getContent().get(1).getValue());
Assert.assertEquals(5, facetQueryResultPage.getContent().get(1).getValueCount());
Assert.assertEquals(1, page.getAllFacets().size());
}
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:28,代码来源:ITestSolrTemplate.java
示例19: findClusterWithFacet
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
public FacetPage<SolrCluster> findClusterWithFacet(
String query,
Set<String> sequenceFilters,
Set<String> modNameFilters,
Set<String> speciesNameFilters) {
// search query
SimpleFacetQuery search = new SimpleFacetQuery();
// searhc criteria
Criteria conditions = createSearchConditions(query);
search.addCriteria(conditions);
// filtering
List<FilterQuery> filterQueries = createFilterQuery(sequenceFilters, modNameFilters, speciesNameFilters);
if (filterQueries != null && !filterQueries.isEmpty()) {
for (FilterQuery filterQuery : filterQueries) {
search.addFilterQuery(filterQuery);
}
}
// facet
FacetOptions facetOptions = new FacetOptions(ClusterFields.MOD_SYNONYMS, ClusterFields.SPECIES_NAMES);
facetOptions.setFacetLimit(FACET_MIN_COUNT);
search.setFacetOptions(facetOptions);
// turn off pagination
//We are only interesting in the facets, not in the query result
search.setPageRequest(new PageRequest(0, 1));
return solrTemplate.queryForFacetPage(search, SolrCluster.class);
}
开发者ID:PRIDE-Cluster,项目名称:cluster-search,代码行数:33,代码来源:SolrClusterRepositoryImpl.java
示例20: getCategoryFacetCounts
import org.springframework.data.solr.core.query.result.FacetPage; //导入依赖的package包/类
private Map<Category, Long> getCategoryFacetCounts(FacetPage<Book> booksFacetPage) {
Map<Category, Long> facetCounts = new HashMap<Category, Long>();
for (Page<? extends FacetEntry> p : booksFacetPage.getAllFacets()) {
for (FacetEntry facetEntry : p.getContent()) {
Category category = Category.valueOf(facetEntry.getValue().toUpperCase());
facetCounts.put(category, facetEntry.getValueCount());
}
}
return facetCounts;
}
开发者ID:mscharhag,项目名称:Spring-data-solr-example,代码行数:11,代码来源:BookRepositoryTests.java
注:本文中的org.springframework.data.solr.core.query.result.FacetPage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论