use of com.nixmash.blog.solr.model.Product in project nixmash-blog by mintster.
the class SolrProductTests method testCustomQueries.
@Test
public void testCustomQueries() {
// Named Query from named-queries.properties
List<Product> products = repo.findByNameOrCategory(SOLR_STRING, sortByIdDesc());
Assert.assertEquals(1, products.size());
// Method Name Query test for findByPopularityGreaterThanEqual()
Product product = SolrTestUtils.createProduct(PRODUCT_ID);
repo.save(product);
Page<Product> popularProducts = repo.findByPopularityGreaterThanEqual(10000, new PageRequest(0, 10));
Assert.assertEquals(1, popularProducts.getTotalElements());
Assert.assertEquals(Integer.toString(PRODUCT_ID), popularProducts.getContent().get(0).getId());
}
use of com.nixmash.blog.solr.model.Product in project nixmash-blog by mintster.
the class SolrProductTests method testFacetQuery.
@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());
}
}
use of com.nixmash.blog.solr.model.Product in project nixmash-blog by mintster.
the class SolrProductTests method highlightedResultsShouldContainTermsInBold.
@Test
public void highlightedResultsShouldContainTermsInBold() {
List<Product> baseList = SolrTestUtils.createProductList(10);
repo.save(baseList);
HighlightPage<Product> highlightProductPage = productService.findByHighlightedName("product", new PageRequest(0, 20));
assertTrue(containsSnipplet(highlightProductPage, "<b>product</b>"));
}
use of com.nixmash.blog.solr.model.Product in project nixmash-blog by mintster.
the class SolrProductTests method testProductCRUD.
@Test
public void testProductCRUD() {
long recordCount = repo.count();
// create local product object
Product product = SolrTestUtils.createProduct(PRODUCT_ID);
// save product to Solr Index and confirm index count increased by 1
repo.save(product);
Assert.assertEquals(recordCount + 1, repo.count());
// find single product from Solr
Product loaded = repo.findOne(Integer.toString(PRODUCT_ID));
Assert.assertEquals(product.getName(), loaded.getName());
// update product name in Solr and confirm index count not changed
loaded.setName("changed named");
repo.save(loaded);
Assert.assertEquals(recordCount + 1, repo.count());
// retrieve product from Solr and confirm name change
loaded = repo.findOne(Integer.toString(PRODUCT_ID));
Assert.assertEquals("changed named", loaded.getName());
// delete the test product in Solr and confirm index count equal to initial count
repo.delete(loaded);
Assert.assertEquals(recordCount, repo.count());
}
use of com.nixmash.blog.solr.model.Product in project nixmash-blog by mintster.
the class SolrUtils method highlightPagesToList.
public static List<Product> highlightPagesToList(HighlightPage<Product> productPage) {
List<Product> products = new ArrayList<Product>();
for (HighlightEntry<Product> highlightedProduct : productPage.getHighlighted()) {
Product product = new Product(highlightedProduct.getEntity().getId(), highlightedProduct.getEntity().getName());
products.add(product);
for (HighlightEntry.Highlight highlight : highlightedProduct.getHighlights()) {
for (String snippet : highlight.getSnipplets()) {
if (highlight.getField().getName().equals(IProduct.NAME_FIELD)) {
product.setName(snippet);
}
}
}
}
return products;
}
Aggregations