You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by as...@apache.org on 2009/09/02 11:33:33 UTC

svn commit: r810434 - in /ofbiz/trunk/applications/product: src/org/ofbiz/product/product/ webapp/catalog/WEB-INF/actions/find/ webapp/catalog/find/

Author: ashish
Date: Wed Sep  2 09:33:31 2009
New Revision: 810434

URL: http://svn.apache.org/viewvc?rev=810434&view=rev
Log:
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.

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy
    ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl
    ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=810434&r1=810433&r2=810434&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Wed Sep  2 09:33:31 2009
@@ -1866,6 +1866,49 @@
         }
     }
 
+    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
     // ======================================================================

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?rev=810434&r1=810433&r2=810434&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Wed Sep  2 09:33:31 2009
@@ -42,6 +42,7 @@
 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 @@
         /** 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 @@
             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 @@
         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 @@
             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 @@
         result.put("previousViewSize", previousViewSize);
         result.put("searchConstraintStrings", searchConstraintStrings);
         result.put("searchSortOrderString", searchSortOrderString);
+        result.put("noConditionFind", noConditionFind);
 
         return result;
     }
@@ -962,6 +987,9 @@
         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;

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy?rev=810434&r1=810433&r2=810434&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy Wed Sep  2 09:33:31 2009
@@ -38,6 +38,7 @@
 context.applicationTypes = applicationTypes;
 context.productCategories = productCategories;
 
+context.noConditionFind = result.noConditionFind;
 context.productIds = result.productIds;
 context.viewIndex = result.viewIndex;
 context.viewSize = result.viewSize;

Modified: ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl?rev=810434&r1=810433&r2=810434&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl Wed Sep  2 09:33:31 2009
@@ -24,6 +24,7 @@
     <form name="advtokeywordsearchform" method="post" action="<@o...@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}"/>
@@ -79,6 +80,26 @@
         </#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}:
           </td>
           <td valign="middle">

Modified: ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl?rev=810434&r1=810433&r2=810434&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl Wed Sep  2 09:33:31 2009
@@ -73,18 +73,18 @@
           <td align="right">
             <b>
             <#if 0 < viewIndex?int>
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
+              <a href="<@o...@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="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
+              | <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
             </#if>
             <#if paging == "Y">
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
+              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
             <#else>
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
+              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
             </#if>
             </b>
           </td>
@@ -120,18 +120,18 @@
           <td align="right">
             <b>
             <#if 0 < viewIndex?int>
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> |
+              <a href="<@o...@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="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
+              | <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a>
             </#if>
             <#if paging == "Y">
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
+              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOff}</a>
             <#else>
-              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
+              <a href="<@o...@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPagingOn}</a>
             </#if>
             </b>
           </td>