コード例 #1
0
  @Test
  public void testFacetOnMultipleFields() {
    FacetPage<ProductBean> facetPage =
        repo.findAllFacetOnPopularityAndAvailable(new PageRequest(0, 10));
    Assert.assertEquals(2, facetPage.getFacetFields().size());

    Page<FacetFieldEntry> popularityPage =
        facetPage.getFacetResultPage(new SimpleField("popularity"));
    Assert.assertEquals(3, popularityPage.getContent().size());
    for (FacetFieldEntry entry : popularityPage) {
      Assert.assertEquals("popularity", entry.getField().getName());
    }

    Page<FacetFieldEntry> availablePage = facetPage.getFacetResultPage(new SimpleField("inStock"));
    Assert.assertEquals(2, availablePage.getContent().size());
    for (FacetFieldEntry entry : availablePage) {
      Assert.assertEquals("inStock", entry.getField().getName());
    }
  }
コード例 #2
0
 @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());
   }
 }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @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());
    }
  }