Skip to content

Commit

Permalink
[ YC-731 ] Optimise full text search query builder for deep category …
Browse files Browse the repository at this point in the history
…hierarchies

- added parent categories to index
- added new categories with parents query builder
- modified brands retrieval
  • Loading branch information
denyspavlov committed Jul 13, 2016
1 parent ad72eeb commit 5c1fcc2
Show file tree
Hide file tree
Showing 39 changed files with 582 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public List<Category> findByProductId(final long productId) {
"categoryService-categoryIdsWithLinks",
"categoryService-categoryHasSubcategory",
"categoryService-byId",
"categoryService-categoryParentsIds",
"shopService-shopCategoriesIds",
"shopService-shopAllCategoriesIds"
}, allEntries = true)
Expand Down Expand Up @@ -505,6 +506,7 @@ public Category create(Category instance) {
"categoryService-categoryIdsWithLinks",
"categoryService-categoryHasSubcategory",
"categoryService-byId",
"categoryService-categoryParentsIds",
"shopService-shopCategoriesIds",
"shopService-shopAllCategoriesIds"
}, allEntries = true)
Expand Down Expand Up @@ -539,7 +541,8 @@ public Category update(Category instance) {
"categoryService-childCategoriesRecursiveIdsWithLinks",
"categoryService-categoryIdsWithLinks",
"categoryService-categoryHasSubcategory",
"categoryService-byId"
"categoryService-byId",
"categoryService-categoryParentsIds"
}, allEntries = true)
public void delete(Category instance) {
super.delete(instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,8 @@ public List<Product> getProductByIdList(final List idList) {
* {@inheritDoc}
*/
@Cacheable(value = "productService-distinctBrands")
public List<FilteredNavigationRecord> getDistinctBrands(final String locale, final List categories) {
List<Object[]> list = productDao.findQueryObjectsByNamedQuery(
"PRODUCTS.BRANDS.BY.ASSIGNED.CATEGORIES",
categories);
public List<FilteredNavigationRecord> getDistinctBrands(final String locale) {
List<Object[]> list = productDao.findQueryObjectsByNamedQuery("PRODUCTS.BRANDS.ALL");

final List<FilteredNavigationRecord> records = constructBrandFilteredNavigationRecords(list);
Collections.sort(
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/resources/cache-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@
<constructor-arg index="0" value="categoryService-byId"/>
<constructor-arg index="1" value="key"/>
</bean>

<bean class="org.yes.cart.domain.misc.Pair">
<constructor-arg index="0" value="categoryService-categoryParentsIds"/>
<constructor-arg index="1" value="key"/>
</bean>
<bean class="org.yes.cart.domain.misc.Pair">
<constructor-arg index="0" value="contentService-rootContent"/>
<constructor-arg index="1" value="all"/>
Expand Down Expand Up @@ -322,7 +325,10 @@
<constructor-arg index="0" value="categoryService-byId"/>
<constructor-arg index="1" value="key"/>
</bean>

<bean class="org.yes.cart.domain.misc.Pair">
<constructor-arg index="0" value="categoryService-categoryParentsIds"/>
<constructor-arg index="1" value="key"/>
</bean>
<bean class="org.yes.cart.domain.misc.Pair">
<constructor-arg index="0" value="contentService-rootContent"/>
<constructor-arg index="1" value="all"/>
Expand Down
14 changes: 8 additions & 6 deletions core/src/main/resources/core-services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</bean>
<bean id="brandLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductBrandSearchQueryBuilder"/>
<bean id="productCategoryLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductCategorySearchQueryBuilder"/>
<bean id="productCategoryIncludingParentsLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductCategoryIncludingParentsSearchQueryBuilder"/>
<bean id="productShopLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductShopSearchQueryBuilder"/>
<bean id="productShopInStockLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductShopInStockSearchQueryBuilder"/>
<bean id="productShopHasPriceLuceneQueryBuilder" class="org.yes.cart.domain.query.impl.ProductShopHasPriceSearchQueryBuilder"/>
Expand Down Expand Up @@ -71,12 +72,13 @@
<entry key="price" value-ref="priceLuceneQueryBuilder"/>

<!-- Internal -->
<entry key="attribute.attribute" value-ref="attributeLuceneQueryBuilder"/>
<entry key="productCategory.category" value-ref="productCategoryLuceneQueryBuilder"/>
<entry key="productShopId" value-ref="productShopLuceneQueryBuilder"/>
<entry key="productInStockShopId" value-ref="productShopInStockLuceneQueryBuilder"/>
<entry key="productHasPriceShopId" value-ref="productShopHasPriceLuceneQueryBuilder"/>
<entry key="featured" value-ref="featuredProductLuceneQueryBuilder"/>
<entry key="attribute.attribute" value-ref="attributeLuceneQueryBuilder"/>
<entry key="productCategory.category" value-ref="productCategoryLuceneQueryBuilder"/>
<entry key="productCategory.category.inc.parents" value-ref="productCategoryIncludingParentsLuceneQueryBuilder"/>
<entry key="productShopId" value-ref="productShopLuceneQueryBuilder"/>
<entry key="productInStockShopId" value-ref="productShopInStockLuceneQueryBuilder"/>
<entry key="productHasPriceShopId" value-ref="productShopHasPriceLuceneQueryBuilder"/>
<entry key="featured" value-ref="featuredProductLuceneQueryBuilder"/>
</map>
</constructor-arg>
<constructor-arg index="4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testRun() throws Exception {

productService.reindexProduct(product.getId());

final NavigationContext context = luceneQueryFactory.getFilteredNavigationQueryChain(10L, null,
final NavigationContext context = luceneQueryFactory.getFilteredNavigationQueryChain(10L, null, false,
Collections.singletonMap(ProductSearchQueryBuilder.PRODUCT_ID_FIELD, (List) Arrays.asList("9998")));

List<ProductSearchResultDTO> rez = productService.getProductSearchResultDTOByQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testRun() throws Exception {

productService.reindexProduct(product.getId());

final NavigationContext context = luceneQueryFactory.getFilteredNavigationQueryChain(10L, null,
final NavigationContext context = luceneQueryFactory.getFilteredNavigationQueryChain(10L, null, false,
Collections.singletonMap(ProductSearchQueryBuilder.PRODUCT_ID_FIELD, (List) Arrays.asList("9998")));

List<ProductSearchResultDTO> rez = productService.getProductSearchResultDTOByQuery(
Expand Down
Loading

0 comments on commit 5c1fcc2

Please sign in to comment.