Applied patch from jira issue OFBIZ-2886 Add support on advanced search functionality (Internal Name, Product Name field & noCondition find option is provided for searching).
Thanks Amit & Rishi for the contribution. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@810434 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1866,6 +1866,49 @@ public class ProductSearch {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProductFieldConstraint extends ProductSearchConstraint {
|
||||
public static final String constraintName = "ProductField";
|
||||
protected String keyword;
|
||||
protected String productFieldName;
|
||||
|
||||
public ProductFieldConstraint(String keyword, String productFieldName) {
|
||||
this.keyword = keyword;
|
||||
this.productFieldName = productFieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConstraint(ProductSearchContext productSearchContext) {
|
||||
productSearchContext.dynamicViewEntity.addAlias("PROD", productFieldName, null, null, null, null, null);
|
||||
productSearchContext.entityConditionList.add(EntityCondition.makeCondition(productFieldName ,EntityOperator.LIKE, keyword + "%"));
|
||||
productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.keyword)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) {
|
||||
return UtilProperties.getMessage(resource, "ProductKeywords", locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
ProductSearchConstraint psc = (ProductSearchConstraint) obj;
|
||||
if (psc instanceof ProductFieldConstraint) {
|
||||
ProductFieldConstraint that = (ProductFieldConstraint) psc;
|
||||
if (this.keyword == null) {
|
||||
if (that.keyword != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!this.keyword.equals(that.keyword)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Result Sort Classes
|
||||
// ======================================================================
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.ofbiz.base.util.UtilDateTime;
|
||||
import org.ofbiz.base.util.UtilGenerics;
|
||||
import org.ofbiz.base.util.UtilHttp;
|
||||
import org.ofbiz.base.util.UtilMisc;
|
||||
import org.ofbiz.base.util.UtilProperties;
|
||||
import org.ofbiz.base.util.UtilValidate;
|
||||
import org.ofbiz.entity.GenericDelegator;
|
||||
import org.ofbiz.entity.GenericEntityException;
|
||||
@@ -87,7 +88,9 @@ public class ProductSearchSession {
|
||||
/** Basic copy constructor */
|
||||
public ProductSearchOptions(ProductSearchOptions productSearchOptions) {
|
||||
this.constraintList = FastList.newInstance();
|
||||
this.constraintList.addAll(productSearchOptions.constraintList);
|
||||
if (UtilValidate.isNotEmpty(productSearchOptions.constraintList)) {
|
||||
this.constraintList.addAll(productSearchOptions.constraintList);
|
||||
}
|
||||
this.topProductCategoryId = productSearchOptions.topProductCategoryId;
|
||||
this.resultSortOrder = productSearchOptions.resultSortOrder;
|
||||
this.viewIndex = productSearchOptions.viewIndex;
|
||||
@@ -593,6 +596,20 @@ public class ProductSearchSession {
|
||||
constraintsChanged = true;
|
||||
}
|
||||
|
||||
// if productName were specified, add a constraint for them
|
||||
if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_PRODUCT_NAME"))) {
|
||||
String productName = (String) parameters.get("SEARCH_PRODUCT_NAME");
|
||||
searchAddConstraint(new ProductSearch.ProductFieldConstraint(productName, "productName"), session);
|
||||
constraintsChanged = true;
|
||||
}
|
||||
|
||||
// if internalName were specified, add a constraint for them
|
||||
if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_INTERNAL_PROD_NAME"))) {
|
||||
String internalName = (String) parameters.get("SEARCH_INTERNAL_PROD_NAME");
|
||||
searchAddConstraint(new ProductSearch.ProductFieldConstraint(internalName, "internalName"), session);
|
||||
constraintsChanged = true;
|
||||
}
|
||||
|
||||
for (int kwNum = 1; kwNum < 10; kwNum++) {
|
||||
if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_STRING" + kwNum))) {
|
||||
String keywordString = (String) parameters.get("SEARCH_STRING" + kwNum);
|
||||
@@ -862,8 +879,13 @@ public class ProductSearchSession {
|
||||
List<String> productIds = FastList.newInstance();
|
||||
String visitId = VisitHandler.getVisitId(session);
|
||||
List<ProductSearchConstraint> productSearchConstraintList = ProductSearchOptions.getConstraintList(session);
|
||||
// if no constraints, don't do a search...
|
||||
if (UtilValidate.isNotEmpty(productSearchConstraintList)) {
|
||||
Map<String, Object> requestParams = UtilHttp.getParameterMap(request);
|
||||
String noConditionFind = (String) requestParams.get("noConditionFind");
|
||||
if (UtilValidate.isEmpty(noConditionFind)) {
|
||||
noConditionFind = UtilProperties.getPropertyValue("widget", "widget.defaultNoConditionFind");
|
||||
}
|
||||
// if noConditionFind to Y then find without conditions otherwise search according to constraints.
|
||||
if ("Y".equals(noConditionFind) || UtilValidate.isNotEmpty(productSearchConstraintList)) {
|
||||
// if the search options have changed since the last search, put at the beginning of the options history list
|
||||
checkSaveSearchOptionsHistory(session);
|
||||
|
||||
@@ -914,7 +936,9 @@ public class ProductSearchSession {
|
||||
ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(request);
|
||||
|
||||
ProductSearchContext productSearchContext = new ProductSearchContext(delegator, visitId);
|
||||
productSearchContext.addProductSearchConstraints(productSearchConstraintList);
|
||||
if (UtilValidate.isNotEmpty(productSearchConstraintList)) {
|
||||
productSearchContext.addProductSearchConstraints(productSearchConstraintList);
|
||||
}
|
||||
productSearchContext.setResultSortOrder(resultSortOrder);
|
||||
productSearchContext.setResultOffset(resultOffset);
|
||||
productSearchContext.setMaxResults(maxResults);
|
||||
@@ -951,6 +975,7 @@ public class ProductSearchSession {
|
||||
result.put("previousViewSize", previousViewSize);
|
||||
result.put("searchConstraintStrings", searchConstraintStrings);
|
||||
result.put("searchSortOrderString", searchSortOrderString);
|
||||
result.put("noConditionFind", noConditionFind);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -962,6 +987,9 @@ public class ProductSearchSession {
|
||||
StringBuilder searchParamString = new StringBuilder();
|
||||
|
||||
List<ProductSearchConstraint> constraintList = productSearchOptions.getConstraintList();
|
||||
if (UtilValidate.isEmpty(constraintList)) {
|
||||
constraintList = new ArrayList<ProductSearchConstraint>();
|
||||
}
|
||||
int categoriesCount = 0;
|
||||
int featuresCount = 0;
|
||||
int featureCategoriesCount = 0;
|
||||
|
||||
@@ -38,6 +38,7 @@ productCategories = delegator.findList("ProductCategory", expr, null, ['descript
|
||||
context.applicationTypes = applicationTypes;
|
||||
context.productCategories = productCategories;
|
||||
|
||||
context.noConditionFind = result.noConditionFind;
|
||||
context.productIds = result.productIds;
|
||||
context.viewIndex = result.viewIndex;
|
||||
context.viewSize = result.viewSize;
|
||||
|
||||
@@ -24,6 +24,7 @@ under the License.
|
||||
<form name="advtokeywordsearchform" method="post" action="<@ofbizUrl>keywordsearch</@ofbizUrl>" style="margin: 0;">
|
||||
<input type="hidden" name="VIEW_SIZE" value="25"/>
|
||||
<input type="hidden" name="PAGING" value="Y"/>
|
||||
<input type="hidden" name="noConditionFind" value="Y"/>
|
||||
<table cellspacing="0" class="basic-table">
|
||||
<#if searchCategory?has_content>
|
||||
<input type="hidden" name="SEARCH_CATEGORY_ID" value="${searchCategoryId?if_exists}"/>
|
||||
@@ -77,6 +78,26 @@ under the License.
|
||||
</td>
|
||||
</tr>
|
||||
</#if>
|
||||
<tr>
|
||||
<td class="label" align="right" valign="top">
|
||||
${uiLabelMap.ProductProductName}:
|
||||
</td>
|
||||
<td valign="middle">
|
||||
<div>
|
||||
<input type="text" name="SEARCH_PRODUCT_NAME" size="20" value="${requestParameters.SEARCH_PRODUCT_NAME?if_exists}"/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" align="right" valign="top">
|
||||
${uiLabelMap.ProductInternalName}:
|
||||
</td>
|
||||
<td valign="middle">
|
||||
<div>
|
||||
<input type="text" name="SEARCH_INTERNAL_PROD_NAME" size="20" value="${requestParameters.SEARCH_INTERNAL_PROD_NAME?if_exists}"/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label" align="right" valign="top">
|
||||
${uiLabelMap.ProductKeywords}:
|
||||
|
||||
@@ -73,18 +73,18 @@ under the License.
|
||||
<td align="right">
|
||||
<b>
|
||||
<#if 0 < viewIndex?int>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
|
||||
</#if>
|
||||
<#if 0 < listSize?int>
|
||||
${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize}
|
||||
</#if>
|
||||
<#if highIndex?int < listSize?int>
|
||||
| <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
|
||||
| <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
|
||||
</#if>
|
||||
<#if paging == "Y">
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=99999/~clearSearch=N/~PAGING=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=99999/~clearSearch=N/~PAGING=N/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
|
||||
<#else>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=${previousViewSize}/~clearSearch=N/~PAGING=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=${previousViewSize}/~clearSearch=N/~PAGING=Y/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
|
||||
</#if>
|
||||
</b>
|
||||
</td>
|
||||
@@ -120,18 +120,18 @@ under the License.
|
||||
<td align="right">
|
||||
<b>
|
||||
<#if 0 < viewIndex?int>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
|
||||
</#if>
|
||||
<#if 0 < listSize?int>
|
||||
${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize}
|
||||
</#if>
|
||||
<#if highIndex?int < listSize?int>
|
||||
| <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
|
||||
| <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N/~PAGING=${paging}/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
|
||||
</#if>
|
||||
<#if paging == "Y">
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=99999/~clearSearch=N/~PAGING=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=99999/~clearSearch=N/~PAGING=N/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
|
||||
<#else>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=${previousViewSize}/~clearSearch=N/~PAGING=Y</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
|
||||
<a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=0/~VIEW_SIZE=${previousViewSize}/~clearSearch=N/~PAGING=Y/~noConditionFind=${noConditionFind}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
|
||||
</#if>
|
||||
</b>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user