1 24 package org.ofbiz.product.product; 25 26 import java.io.IOException ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.HashMap ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 import java.util.LinkedList ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Set ; 36 37 import javax.servlet.ServletContext ; 38 import javax.servlet.http.HttpServletRequest ; 39 import javax.servlet.http.HttpServletResponse ; 40 import javax.servlet.http.HttpSession ; 41 42 import org.ofbiz.base.util.Debug; 43 import org.ofbiz.base.util.UtilHttp; 44 import org.ofbiz.base.util.UtilMisc; 45 import org.ofbiz.base.util.UtilValidate; 46 import org.ofbiz.webapp.stats.VisitHandler; 47 import org.ofbiz.webapp.control.RequestHandler; 48 import org.ofbiz.entity.GenericDelegator; 49 import org.ofbiz.entity.GenericEntityException; 50 import org.ofbiz.entity.GenericValue; 51 import org.ofbiz.entity.util.EntityUtil; 52 import org.ofbiz.product.catalog.CatalogWorker; 53 import org.ofbiz.product.feature.ParametricSearch; 54 import org.ofbiz.product.product.ProductSearch.CategoryConstraint; 55 import org.ofbiz.product.product.ProductSearch.FeatureConstraint; 56 import org.ofbiz.product.product.ProductSearch.KeywordConstraint; 57 import org.ofbiz.product.product.ProductSearch.ProductSearchConstraint; 58 import org.ofbiz.product.product.ProductSearch.ProductSearchContext; 59 import org.ofbiz.product.product.ProductSearch.ResultSortOrder; 60 import org.ofbiz.product.product.ProductSearch.SortKeywordRelevancy; 61 import org.ofbiz.product.store.ProductStoreWorker; 62 63 70 public class ProductSearchSession { 71 72 public static final String module = ProductSearchSession.class.getName(); 73 74 public static class ProductSearchOptions implements java.io.Serializable { 75 protected List constraintList = null; 76 protected ResultSortOrder resultSortOrder = null; 77 protected Integer viewIndex = null; 78 protected Integer viewSize = null; 79 protected boolean changed = false; 80 81 public ProductSearchOptions() { } 82 83 84 public ProductSearchOptions(ProductSearchOptions productSearchOptions) { 85 this.constraintList = new LinkedList (productSearchOptions.constraintList); 86 this.resultSortOrder = productSearchOptions.resultSortOrder; 87 this.viewIndex = productSearchOptions.viewIndex; 88 this.viewSize = productSearchOptions.viewSize; 89 this.changed = productSearchOptions.changed; 90 } 91 92 public List getConstraintList() { 93 return this.constraintList; 94 } 95 public static List getConstraintList(HttpSession session) { 96 return getProductSearchOptions(session).constraintList; 97 } 98 public static void addConstraint(ProductSearchConstraint productSearchConstraint, HttpSession session) { 99 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 100 if (productSearchOptions.constraintList == null) { 101 productSearchOptions.constraintList = new LinkedList (); 102 } 103 if (!productSearchOptions.constraintList.contains(productSearchConstraint)) { 104 productSearchOptions.constraintList.add(productSearchConstraint); 105 productSearchOptions.changed = true; 106 } 107 } 108 109 public ResultSortOrder getResultSortOrder() { 110 if (this.resultSortOrder == null) { 111 this.resultSortOrder = new SortKeywordRelevancy(); 112 this.changed = true; 113 } 114 return this.resultSortOrder; 115 } 116 public static ResultSortOrder getResultSortOrder(HttpSession session) { 117 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 118 return productSearchOptions.getResultSortOrder(); 119 } 120 public static void setResultSortOrder(ResultSortOrder resultSortOrder, HttpSession session) { 121 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 122 productSearchOptions.resultSortOrder = resultSortOrder; 123 productSearchOptions.changed = true; 124 } 125 126 public static void clearSearchOptions(HttpSession session) { 127 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 128 productSearchOptions.constraintList = null; 129 productSearchOptions.resultSortOrder = null; 130 } 131 132 public void clearViewInfo() { 133 this.viewIndex = null; 134 this.viewSize = null; 135 } 136 137 140 public Integer getViewIndex() { 141 return viewIndex; 142 } 143 146 public void setViewIndex(Integer viewIndex) { 147 this.viewIndex = viewIndex; 148 } 149 152 public Integer getViewSize() { 153 return viewSize; 154 } 155 158 public void setViewSize(Integer viewSize) { 159 this.viewSize = viewSize; 160 } 161 162 public List searchGetConstraintStrings(boolean detailed, GenericDelegator delegator) { 163 List productSearchConstraintList = this.getConstraintList(); 164 List constraintStrings = new ArrayList (); 165 if (productSearchConstraintList == null) { 166 return constraintStrings; 167 } 168 Iterator productSearchConstraintIter = productSearchConstraintList.iterator(); 169 while (productSearchConstraintIter.hasNext()) { 170 ProductSearchConstraint productSearchConstraint = (ProductSearchConstraint) productSearchConstraintIter.next(); 171 if (productSearchConstraint == null) continue; 172 String constraintString = productSearchConstraint.prettyPrintConstraint(delegator, detailed); 173 if (UtilValidate.isNotEmpty(constraintString)) { 174 constraintStrings.add(constraintString); 175 } else { 176 constraintStrings.add("Description not available"); 177 } 178 } 179 return constraintStrings; 180 } 181 } 182 183 public static ProductSearchOptions getProductSearchOptions(HttpSession session) { 184 ProductSearchOptions productSearchOptions = (ProductSearchOptions) session.getAttribute("_PRODUCT_SEARCH_OPTIONS_CURRENT_"); 185 if (productSearchOptions == null) { 186 productSearchOptions = new ProductSearchOptions(); 187 session.setAttribute("_PRODUCT_SEARCH_OPTIONS_CURRENT_", productSearchOptions); 188 } 189 return productSearchOptions; 190 } 191 192 public static void checkSaveSearchOptionsHistory(HttpSession session) { 193 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 194 if (productSearchOptions.changed) { 196 List optionsHistoryList = getSearchOptionsHistoryList(session); 197 optionsHistoryList.add(0, new ProductSearchOptions(productSearchOptions)); 198 productSearchOptions.changed = false; 199 } 200 } 201 public static List getSearchOptionsHistoryList(HttpSession session) { 202 List optionsHistoryList = (List ) session.getAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_"); 203 if (optionsHistoryList == null) { 204 optionsHistoryList = new LinkedList (); 205 session.setAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_", optionsHistoryList); 206 } 207 return optionsHistoryList; 208 } 209 public static void clearSearchOptionsHistoryList(HttpSession session) { 210 session.removeAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_"); 211 } 212 213 public static void setCurrentSearchFromHistory(int index, boolean removeOld, HttpSession session) { 214 List searchOptionsHistoryList = getSearchOptionsHistoryList(session); 215 if (index < searchOptionsHistoryList.size()) { 216 ProductSearchOptions productSearchOptions = (ProductSearchOptions) searchOptionsHistoryList.get(index); 217 if (removeOld) { 218 searchOptionsHistoryList.remove(index); 219 } 220 if (productSearchOptions != null) { 221 session.setAttribute("_PRODUCT_SEARCH_OPTIONS_CURRENT_", new ProductSearchOptions(productSearchOptions)); 222 } 223 } else { 224 throw new IllegalArgumentException ("Could not set current search options to history index [" + index + "], only [" + searchOptionsHistoryList.size() + "] entries in the history list."); 225 } 226 } 227 228 public static String clearSearchOptionsHistoryList(HttpServletRequest request, HttpServletResponse response) { 229 HttpSession session = request.getSession(); 230 clearSearchOptionsHistoryList(session); 231 return "success"; 232 } 233 234 public static String setCurrentSearchFromHistory(HttpServletRequest request, HttpServletResponse response) { 235 HttpSession session = request.getSession(); 236 String searchHistoryIndexStr = request.getParameter("searchHistoryIndex"); 237 String removeOldStr = request.getParameter("removeOld"); 238 239 if (UtilValidate.isEmpty(searchHistoryIndexStr)) { 240 request.setAttribute("_ERROR_MESSAGE_", "No search history index passed, cannot set current search to previous."); 241 return "error"; 242 } 243 244 try { 245 int searchHistoryIndex = Integer.parseInt(searchHistoryIndexStr); 246 boolean removeOld = true; 247 if (UtilValidate.isNotEmpty(removeOldStr)) { 248 removeOld = !"false".equals(removeOldStr); 249 } 250 setCurrentSearchFromHistory(searchHistoryIndex, removeOld, session); 251 } catch (Exception e) { 252 request.setAttribute("_ERROR_MESSAGE_", e.toString()); 253 return "error"; 254 } 255 256 return "success"; 257 } 258 259 260 public static final String checkDoKeywordOverride(HttpServletRequest request, HttpServletResponse response) { 261 HttpSession session = request.getSession(); 262 GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); 263 Map requestParams = UtilHttp.getParameterMap(request); 264 ProductSearchSession.processSearchParameters(requestParams, session); 265 266 String productStoreId = ProductStoreWorker.getProductStoreId(request); 268 if (productStoreId != null) { 269 Set keywords = new HashSet (); 271 List constraintList = ProductSearchOptions.getConstraintList(session); 272 if (constraintList != null) { 273 Iterator constraintIter = constraintList.iterator(); 274 while (constraintIter.hasNext()) { 275 Object constraint = constraintIter.next(); 276 if (constraint instanceof KeywordConstraint) { 277 KeywordConstraint keywordConstraint = (KeywordConstraint) constraint; 278 Set keywordSet = keywordConstraint.makeFullKeywordSet(delegator); 279 if (keywordSet != null) keywords.addAll(keywordSet); 280 } 281 } 282 } 283 284 if (keywords.size() > 0) { 285 List productStoreKeywordOvrdList = null; 286 try { 287 productStoreKeywordOvrdList = delegator.findByAndCache("ProductStoreKeywordOvrd", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("-fromDate")); 288 productStoreKeywordOvrdList = EntityUtil.filterByDate(productStoreKeywordOvrdList, true); 289 } catch (GenericEntityException e) { 290 Debug.logError(e, "Error reading ProductStoreKeywordOvrd list, not doing keyword override", module); 291 } 292 293 if (productStoreKeywordOvrdList != null && productStoreKeywordOvrdList.size() > 0) { 294 Iterator productStoreKeywordOvrdIter = productStoreKeywordOvrdList.iterator(); 295 while (productStoreKeywordOvrdIter.hasNext()) { 296 GenericValue productStoreKeywordOvrd = (GenericValue) productStoreKeywordOvrdIter.next(); 297 String ovrdKeyword = productStoreKeywordOvrd.getString("keyword"); 298 if (keywords.contains(ovrdKeyword)) { 299 String targetTypeEnumId = productStoreKeywordOvrd.getString("targetTypeEnumId"); 300 String target = productStoreKeywordOvrd.getString("target"); 301 ServletContext ctx = (ServletContext ) request.getAttribute("servletContext"); 302 RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); 303 if ("KOTT_PRODCAT".equals(targetTypeEnumId)) { 304 String requestName = "/category/~category_id=" + target; 305 target = rh.makeLink(request, response, requestName, false, false, false); 306 } else if ("KOTT_PRODUCT".equals(targetTypeEnumId)) { 307 String requestName = "/product/~product_id=" + target; 308 target = rh.makeLink(request, response, requestName, false, false, false); 309 } else if ("KOTT_OFBURL".equals(targetTypeEnumId)) { 310 target = rh.makeLink(request, response, target, false, false, false); 311 } else if ("KOTT_AURL".equals(targetTypeEnumId)) { 312 } else { 314 Debug.logError("The targetTypeEnumId [] is not recognized, not doing keyword override", module); 315 continue; 317 } 318 try { 319 response.sendRedirect(target); 320 return "none"; 321 } catch (IOException e) { 322 Debug.logError(e, "Could not send redirect to: " + target, module); 323 continue; 324 } 325 } 326 } 327 } 328 } 329 } 330 331 return "success"; 332 } 333 334 public static ArrayList searchDo(HttpSession session, GenericDelegator delegator, String prodCatalogId) { 335 String visitId = VisitHandler.getVisitId(session); 336 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 337 List productSearchConstraintList = productSearchOptions.getConstraintList(); 338 if (productSearchConstraintList == null || productSearchConstraintList.size() == 0) { 339 return new ArrayList (); 341 } 342 343 productSearchConstraintList = ensureViewAllowConstraint(productSearchConstraintList, prodCatalogId, delegator); 345 ResultSortOrder resultSortOrder = productSearchOptions.getResultSortOrder(); 346 347 checkSaveSearchOptionsHistory(session); 349 350 return ProductSearch.searchProducts(productSearchConstraintList, resultSortOrder, delegator, visitId); 351 } 352 353 public static List ensureViewAllowConstraint(List productSearchConstraintList, String prodCatalogId, GenericDelegator delegator) { 354 String viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, prodCatalogId); 355 if (UtilValidate.isNotEmpty(viewProductCategoryId)) { 356 ProductSearchConstraint viewAllowConstraint = new CategoryConstraint(viewProductCategoryId, true); 357 if (!productSearchConstraintList.contains(viewAllowConstraint)) { 358 productSearchConstraintList = new ArrayList (productSearchConstraintList); 360 productSearchConstraintList.add(viewAllowConstraint); 361 } 362 } 363 return productSearchConstraintList; 364 } 365 366 public static void searchClear(HttpSession session) { 367 ProductSearchOptions.clearSearchOptions(session); 368 } 369 370 public static List searchGetConstraintStrings(boolean detailed, HttpSession session, GenericDelegator delegator) { 371 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 372 return productSearchOptions.searchGetConstraintStrings(detailed, delegator); 373 } 374 375 public static String searchGetSortOrderString(boolean detailed, HttpSession session) { 376 ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(session); 377 if (resultSortOrder == null) return ""; 378 return resultSortOrder.prettyPrintSortOrder(detailed); 379 } 380 381 public static void searchSetSortOrder(ResultSortOrder resultSortOrder, HttpSession session) { 382 ProductSearchOptions.setResultSortOrder(resultSortOrder, session); 383 } 384 385 public static void searchAddFeatureIdConstraints(Collection featureIds, HttpSession session) { 386 if (featureIds == null || featureIds.size() == 0) { 387 return; 388 } 389 Iterator featureIdIter = featureIds.iterator(); 390 while (featureIdIter.hasNext()) { 391 String productFeatureId = (String ) featureIdIter.next(); 392 searchAddConstraint(new FeatureConstraint(productFeatureId), session); 393 } 394 } 395 396 public static void searchAddConstraint(ProductSearchConstraint productSearchConstraint, HttpSession session) { 397 ProductSearchOptions.addConstraint(productSearchConstraint, session); 398 } 399 400 public static void searchRemoveConstraint(int index, HttpSession session) { 401 List productSearchConstraintList = ProductSearchOptions.getConstraintList(session); 402 if (productSearchConstraintList == null) { 403 return; 404 } else if (index >= productSearchConstraintList.size()) { 405 return; 406 } else { 407 productSearchConstraintList.remove(index); 408 } 409 } 410 411 public static void processSearchParameters(Map parameters, HttpSession session) { 412 boolean constraintsChanged = false; 413 414 String clearSearchString = (String ) parameters.get("clearSearch"); 416 if (!"N".equals(clearSearchString)) { 417 searchClear(session); 418 constraintsChanged = true; 419 } else { 420 String removeConstraint = (String ) parameters.get("removeConstraint"); 421 if (UtilValidate.isNotEmpty(removeConstraint)) { 422 try { 423 searchRemoveConstraint(Integer.parseInt(removeConstraint), session); 424 constraintsChanged = true; 425 } catch (Exception e) { 426 Debug.logError(e, "Error removing constraint [" + removeConstraint + "]", module); 427 } 428 } 429 } 430 431 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_CATEGORY_ID"))) { 433 String searchCategoryId = (String ) parameters.get("SEARCH_CATEGORY_ID"); 434 String searchSubCategories = (String ) parameters.get("SEARCH_SUB_CATEGORIES"); 435 searchAddConstraint(new ProductSearch.CategoryConstraint(searchCategoryId, !"N".equals(searchSubCategories)), session); 436 constraintsChanged = true; 437 } 438 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_CATEGORY_ID2"))) { 439 String searchCategoryId = (String ) parameters.get("SEARCH_CATEGORY_ID2"); 440 String searchSubCategories = (String ) parameters.get("SEARCH_SUB_CATEGORIES2"); 441 searchAddConstraint(new ProductSearch.CategoryConstraint(searchCategoryId, !"N".equals(searchSubCategories)), session); 442 constraintsChanged = true; 443 } 444 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_CATEGORY_ID3"))) { 445 String searchCategoryId = (String ) parameters.get("SEARCH_CATEGORY_ID3"); 446 String searchSubCategories = (String ) parameters.get("SEARCH_SUB_CATEGORIES3"); 447 searchAddConstraint(new ProductSearch.CategoryConstraint(searchCategoryId, !"N".equals(searchSubCategories)), session); 448 constraintsChanged = true; 449 } 450 451 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_STRING"))) { 453 String keywordString = (String ) parameters.get("SEARCH_STRING"); 454 String searchOperator = (String ) parameters.get("SEARCH_OPERATOR"); 455 boolean anyPrefixSuffix = !"N".equals((String ) parameters.get("SEARCH_ANYPRESUF")); 457 searchAddConstraint(new ProductSearch.KeywordConstraint(keywordString, anyPrefixSuffix, anyPrefixSuffix, null, "AND".equals(searchOperator)), session); 458 constraintsChanged = true; 459 } 460 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_STRING2"))) { 461 String keywordString = (String ) parameters.get("SEARCH_STRING2"); 462 String searchOperator = (String ) parameters.get("SEARCH_OPERATOR2"); 463 boolean anyPrefixSuffix = !"N".equals((String ) parameters.get("SEARCH_ANYPRESUF2")); 465 searchAddConstraint(new ProductSearch.KeywordConstraint(keywordString, anyPrefixSuffix, anyPrefixSuffix, null, "AND".equals(searchOperator)), session); 466 constraintsChanged = true; 467 } 468 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_STRING3"))) { 469 String keywordString = (String ) parameters.get("SEARCH_STRING3"); 470 String searchOperator = (String ) parameters.get("SEARCH_OPERATOR3"); 471 boolean anyPrefixSuffix = !"N".equals((String ) parameters.get("SEARCH_ANYPRESUF3")); 473 searchAddConstraint(new ProductSearch.KeywordConstraint(keywordString, anyPrefixSuffix, anyPrefixSuffix, null, "AND".equals(searchOperator)), session); 474 constraintsChanged = true; 475 } 476 477 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_FEAT"))) { 479 searchAddConstraint(new ProductSearch.FeatureConstraint((String ) parameters.get("SEARCH_FEAT")), session); 480 constraintsChanged = true; 481 } 482 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_FEAT2"))) { 483 searchAddConstraint(new ProductSearch.FeatureConstraint((String ) parameters.get("SEARCH_FEAT2")), session); 484 constraintsChanged = true; 485 } 486 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_FEAT3"))) { 487 searchAddConstraint(new ProductSearch.FeatureConstraint((String ) parameters.get("SEARCH_FEAT3")), session); 488 constraintsChanged = true; 489 } 490 491 Map featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(parameters); 493 if (featureIdByType.size() > 0) { 494 constraintsChanged = true; 495 searchAddFeatureIdConstraints(featureIdByType.values(), session); 496 } 497 498 if (UtilValidate.isNotEmpty((String ) parameters.get("SEARCH_SUPPLIER_ID"))) { 500 String supplierPartyId = (String ) parameters.get("SEARCH_SUPPLIER_ID"); 501 searchAddConstraint(new ProductSearch.SupplierConstraint(supplierPartyId), session); 502 constraintsChanged = true; 503 } 504 505 String sortOrder = (String ) parameters.get("sortOrder"); 507 String sortAscending = (String ) parameters.get("sortAscending"); 508 boolean ascending = !"N".equals(sortAscending); 509 if (sortOrder != null) { 510 if (sortOrder.equals("SortKeywordRelevancy")) { 511 searchSetSortOrder(new ProductSearch.SortKeywordRelevancy(), session); 512 } else if (sortOrder.startsWith("SortProductField:")) { 513 String fieldName = sortOrder.substring("SortProductField:".length()); 514 searchSetSortOrder(new ProductSearch.SortProductField(fieldName, ascending), session); 515 } else if (sortOrder.startsWith("SortProductPrice:")) { 516 String priceTypeId = sortOrder.substring("SortProductPrice:".length()); 517 searchSetSortOrder(new ProductSearch.SortProductPrice(priceTypeId, ascending), session); 518 } 519 } 520 521 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 522 if (constraintsChanged) { 523 productSearchOptions.clearViewInfo(); 525 } 526 527 String viewIndexStr = (String ) parameters.get("VIEW_INDEX"); 528 if (UtilValidate.isNotEmpty(viewIndexStr)) { 529 try { 530 productSearchOptions.setViewIndex(Integer.valueOf(viewIndexStr)); 531 } catch (Exception e) { 532 Debug.logError(e, "Error formatting VIEW_INDEX, setting to 0", module); 533 productSearchOptions.setViewIndex(new Integer (0)); 535 } 536 } 537 538 String viewSizeStr = (String ) parameters.get("VIEW_SIZE"); 539 if (UtilValidate.isNotEmpty(viewSizeStr)) { 540 try { 541 productSearchOptions.setViewSize(Integer.valueOf(viewSizeStr)); 542 } catch (Exception e) { 543 Debug.logError(e, "Error formatting VIEW_SIZE, setting to 20", module); 544 productSearchOptions.setViewSize(new Integer (20)); 545 } 546 } 547 } 548 549 public static Map getProductSearchResult(HttpSession session, GenericDelegator delegator, String prodCatalogId) { 550 551 int viewIndex = 0; 553 int viewSize = 20; 554 int highIndex = 0; 555 int lowIndex = 0; 556 int listSize = 0; 557 558 ProductSearchOptions productSearchOptions = getProductSearchOptions(session); 559 560 Integer viewIndexInteger = productSearchOptions.getViewIndex(); 561 if (viewIndexInteger != null) viewIndex = viewIndexInteger.intValue(); 562 Integer viewSizeInteger = productSearchOptions.getViewSize(); 563 if (viewSizeInteger != null) viewSize = viewSizeInteger.intValue(); 564 565 lowIndex = viewIndex * viewSize; 566 highIndex = (viewIndex + 1) * viewSize; 567 568 Integer resultOffset = new Integer (lowIndex + 1); 570 Integer maxResults = new Integer (viewSize); 571 572 ArrayList productIds = null; 574 String visitId = VisitHandler.getVisitId(session); 575 List productSearchConstraintList = ProductSearchOptions.getConstraintList(session); 576 if (productSearchConstraintList != null && productSearchConstraintList.size() > 0) { 578 checkSaveSearchOptionsHistory(session); 580 581 productSearchConstraintList = ensureViewAllowConstraint(productSearchConstraintList, prodCatalogId, delegator); 582 ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(session); 583 584 ProductSearchContext productSearchContext = new ProductSearchContext(delegator, visitId); 585 productSearchContext.addProductSearchConstraints(productSearchConstraintList); 586 productSearchContext.setResultSortOrder(resultSortOrder); 587 productSearchContext.setResultOffset(resultOffset); 588 productSearchContext.setMaxResults(maxResults); 589 590 productIds = productSearchContext.doSearch(); 591 592 Integer totalResults = productSearchContext.getTotalResults(); 593 if (totalResults != null) { 594 listSize = totalResults.intValue(); 595 } 596 } 597 598 if (listSize < highIndex) { 599 highIndex = listSize; 600 } 601 602 List searchConstraintStrings = searchGetConstraintStrings(false, session, delegator); 604 String searchSortOrderString = searchGetSortOrderString(false, session); 605 606 Map result = new HashMap (); 608 609 result.put("productIds", productIds); 610 result.put("viewIndex", new Integer (viewIndex)); 611 result.put("viewSize", new Integer (viewSize)); 612 result.put("listSize", new Integer (listSize)); 613 result.put("lowIndex", new Integer (lowIndex)); 614 result.put("highIndex", new Integer (highIndex)); 615 result.put("searchConstraintStrings", searchConstraintStrings); 616 result.put("searchSortOrderString", searchSortOrderString); 617 618 return result; 619 } 620 } 621 | Popular Tags |