Search in sources :

Example 6 with Product

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Product(com.nixmash.blog.solr.model.Product) Test(org.junit.Test)

Example 7 with Product

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());
    }
}
Also used : FacetFieldEntry(org.springframework.data.solr.core.query.result.FacetFieldEntry) PageRequest(org.springframework.data.domain.PageRequest) Product(com.nixmash.blog.solr.model.Product) Test(org.junit.Test)

Example 8 with Product

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>"));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Product(com.nixmash.blog.solr.model.Product) Test(org.junit.Test)

Example 9 with Product

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());
}
Also used : Product(com.nixmash.blog.solr.model.Product) Test(org.junit.Test)

Example 10 with Product

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;
}
Also used : ArrayList(java.util.ArrayList) IProduct(com.nixmash.blog.solr.model.IProduct) Product(com.nixmash.blog.solr.model.Product) HighlightEntry(org.springframework.data.solr.core.query.result.HighlightEntry)

Aggregations

Product (com.nixmash.blog.solr.model.Product)20 Test (org.junit.Test)10 Point (org.springframework.data.geo.Point)6 PageRequest (org.springframework.data.domain.PageRequest)5 Distance (org.springframework.data.geo.Distance)5 FacetFieldEntry (org.springframework.data.solr.core.query.result.FacetFieldEntry)4 GeoLocationException (com.nixmash.blog.solr.exceptions.GeoLocationException)2 ArrayList (java.util.ArrayList)2 SimpleQuery (org.springframework.data.solr.core.query.SimpleQuery)2 SimpleStringCriteria (org.springframework.data.solr.core.query.SimpleStringCriteria)2 Post (com.nixmash.blog.jpa.model.Post)1 ProductCategory (com.nixmash.blog.mvc.containers.ProductCategory)1 IProduct (com.nixmash.blog.solr.model.IProduct)1 PostDoc (com.nixmash.blog.solr.model.PostDoc)1 MessageFormat (java.text.MessageFormat)1 PagedListHolder (org.springframework.beans.support.PagedListHolder)1 Box (org.springframework.data.geo.Box)1 UncategorizedSolrException (org.springframework.data.solr.UncategorizedSolrException)1 Criteria (org.springframework.data.solr.core.query.Criteria)1 Query (org.springframework.data.solr.core.query.Query)1