示例#1
0
 /** 生成索引 */
 @RequestMapping(value = "/build", method = RequestMethod.POST)
 public @ResponseBody Map<String, Object> build(
     BuildType buildType, Boolean isPurge, Integer first, Integer count) {
   long startTime = System.currentTimeMillis();
   if (first == null || first < 0) {
     first = 0;
   }
   if (count == null || count <= 0) {
     count = 50;
   }
   int buildCount = 0;
   boolean isCompleted = true;
   if (buildType == BuildType.article) {
     if (first == 0 && isPurge != null && isPurge) {
       searchService.purge(Article.class);
     }
     List<Article> articles = articleService.findList(null, null, null, first, count);
     for (Article article : articles) {
       searchService.index(article);
       buildCount++;
     }
     first += articles.size();
     if (articles.size() == count) {
       isCompleted = false;
     }
   } else if (buildType == BuildType.product) {
     if (first == 0 && isPurge != null && isPurge) {
       searchService.purge(Product.class);
     }
     List<Product> products = productService.findList(null, null, null, first, count);
     for (Product product : products) {
       searchService.index(product);
       buildCount++;
     }
     first += products.size();
     if (products.size() == count) {
       isCompleted = false;
     }
   }
   long endTime = System.currentTimeMillis();
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("first", first);
   map.put("buildCount", buildCount);
   map.put("buildTime", endTime - startTime);
   map.put("isCompleted", isCompleted);
   return map;
 }
示例#2
0
  /** 搜索 */
  @RequestMapping(value = "/search", method = RequestMethod.GET)
  public String search(
      String keyword,
      BigDecimal startPrice,
      BigDecimal endPrice,
      OrderType orderType,
      Integer pageNumber,
      Integer pageSize,
      ModelMap model,
      HttpServletRequest request) {
    System.out.println("gwSearch");
    System.out.println("keyword=" + keyword);
    System.out.println("keyword=" + keyword);
    System.out.println("keyword=" + keyword);

    ProductCategory productCategory = productCategoryService.findProductCategoryByKeyword(keyword);

    Map<Attribute, String> attributeValue = new HashMap<Attribute, String>();
    if (productCategory != null) {
      System.out.println("productCategory=" + productCategory.getName());
      System.out.println("productCategory=" + productCategory.getId());
      Set<Attribute> attributes = productCategory.getAttributes();
      for (Attribute attribute : attributes) {
        String value = request.getParameter("attribute_" + attribute.getId());
        if (StringUtils.isNotEmpty(value) && attribute.getOptions().contains(value)) {
          attributeValue.put(attribute, value);
        }
      }
    }

    if (StringUtils.isEmpty(keyword)) {
      return ERROR_VIEW;
    }
    Pageable pageable = null;
    if (pageSize != null) {
      pageable = new Pageable(pageNumber, pageSize);
    } else {
      pageable = new Pageable(pageNumber, DEFAULT_PAGE_SIZE);
    }
    Page<Product> page = searchService.search(keyword, startPrice, endPrice, orderType, pageable);
    List<Product> products = page.getContent();
    System.out.println("page.zlh->" + products);
    model.addAttribute("orderTypes", OrderType.values());
    model.addAttribute("productKeyword", keyword);
    model.addAttribute("startPrice", startPrice);
    model.addAttribute("endPrice", endPrice);
    model.addAttribute("orderType", orderType);
    pageable.setSearchValue(keyword);
    pageable.setSearchProperty("name");
    model.addAttribute(
        "page1",
        productService.findPage(
            productCategory,
            null,
            null,
            null,
            attributeValue,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            null,
            null,
            orderType,
            pageable));
    System.out.println(
        productService
            .findPage(
                productCategory,
                null,
                null,
                null,
                attributeValue,
                startPrice,
                endPrice,
                true,
                true,
                null,
                false,
                null,
                null,
                orderType,
                pageable)
            .getTotal());

    model.addAttribute(
        "page",
        productService.findPageByEntcode(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            true,
            null,
            null,
            null,
            null,
            OrderType.dateDesc,
            pageable));
    System.out.println(
        productService
            .findPageByEntcode(
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                true,
                null,
                null,
                null,
                null,
                OrderType.dateDesc,
                pageable)
            .getTotal());

    return "gw/product/search";
  }