Explorar o código

remove SearchException

sunyj %!s(int64=8) %!d(string=hai) anos
pai
achega
2dec6a7238

+ 2 - 1
mall-search/src/main/java/com/uas/search/controller/IndexController.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -131,7 +132,7 @@ public class IndexController {
 
     @RequestMapping("/updateByNewWords")
     @ResponseBody
-    public Map<String, List<Object>> updateIndexByNewWords(String newWords, HttpServletRequest request) {
+    public Map<String, List<Object>> updateIndexByNewWords(String newWords, HttpServletRequest request) throws IOException {
         return indexService.updateIndexByNewWords(toList(newWords));
     }
 }

+ 18 - 24
mall-search/src/main/java/com/uas/search/controller/OrderSearchController.java

@@ -1,31 +1,25 @@
 package com.uas.search.controller;
 
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import com.uas.search.util.StringUtils;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
 import com.uas.search.constant.model.BaseOrder;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.PageParams.FilterField;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
-import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Order;
-import com.uas.search.model.PurchaseInvoice;
+import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Purchase;
+import com.uas.search.model.PurchaseInvoice;
 import com.uas.search.service.OrderSearchService;
 import com.uas.search.service.OrderSearchService.Table_name;
+import com.uas.search.util.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.*;
 
 /**
  * 订单搜索请求
@@ -44,7 +38,7 @@ public class OrderSearchController {
 	@ResponseBody
 	public SPage<BaseOrder> getOrderIdsWithDetail(String keyword, String tableName, Integer page, Integer size,
 			String status, Long buyeruu, Long buyerenuu, Long sellerenuu, String mintime, String maxtime,
-			HttpServletRequest request) {
+			HttpServletRequest request) throws IOException {
 		Table_name tbName = null;
 		if (!StringUtils.isEmpty(tableName)) {
 			tbName = Table_name.valueOf(tableName);
@@ -108,31 +102,31 @@ public class OrderSearchController {
 			calendar.set(year, month, date, hour, minute, second);
 			return calendar.getTimeInMillis();
 		} catch (Exception e) {
-			throw new SearchException("时间格式错误,示例:'2016-10-10 1:12:20'," + e);
+			throw new IllegalArgumentException("时间格式错误,示例:'2016-10-10 1:12:20'," + e);
 		}
 	}
 
 	@RequestMapping("/order/{id}")
 	@ResponseBody
-	public Order getOrder(@PathVariable Long id, HttpServletRequest request) {
+	public Order getOrder(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return orderSearchService.getOrder(id);
 	}
 
 	@RequestMapping("/orderInvoice/{id}")
 	@ResponseBody
-	public OrderInvoice getOrderInvoice(@PathVariable Long id, HttpServletRequest request) {
+	public OrderInvoice getOrderInvoice(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return orderSearchService.getOrderInvoice(id);
 	}
 
 	@RequestMapping("/purchase/{id}")
 	@ResponseBody
-	public Purchase getPurchase(@PathVariable Long id, HttpServletRequest request) {
+	public Purchase getPurchase(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return orderSearchService.getPurchase(id);
 	}
 
 	@RequestMapping("/purchaseInvoice/{id}")
 	@ResponseBody
-	public PurchaseInvoice getPurchaseInvoice(@PathVariable Long id, HttpServletRequest request) {
+	public PurchaseInvoice getPurchaseInvoice(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return orderSearchService.getPurchaseInvoice(id);
 	}
 

+ 46 - 51
mall-search/src/main/java/com/uas/search/controller/SearchController.java

@@ -1,26 +1,25 @@
 package com.uas.search.controller;
 
-import com.uas.search.util.StringUtils;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.search.constant.model.CollectField;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.PageParams.FilterField;
 import com.uas.search.constant.model.SPage;
 import com.uas.search.dao.ComponentDao;
-import com.uas.search.exception.SearchException;
 import com.uas.search.model.Brand;
 import com.uas.search.model.Component;
 import com.uas.search.model.Goods;
 import com.uas.search.model.Kind;
 import com.uas.search.service.SearchService;
 import com.uas.search.service.impl.IndexServiceImpl;
+import com.uas.search.util.CollectionUtils;
 import com.uas.search.util.FileUtils;
 import com.uas.search.util.SearchUtils;
+import com.uas.search.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import com.uas.search.util.CollectionUtils;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -28,7 +27,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.*;
 import java.util.Map.Entry;
@@ -51,28 +50,28 @@ public class SearchController {
 	@RequestMapping("/kindIds")
 	@ResponseBody
 	public SPage<Long> seachKindIds(@RequestParam String keyword, Integer page, Integer size,
-									HttpServletRequest request) {
+									HttpServletRequest request) throws IOException {
 		return searchService.getKindIds(keyword, page, size);
 	}
 
 	@RequestMapping("/kinds")
 	@ResponseBody
 	public SPage<Map<String, Object>> seachKinds(@RequestParam String keyword, Integer page, Integer size,
-												 HttpServletRequest request) {
+												 HttpServletRequest request) throws IOException {
 		return searchService.getKinds(keyword, page, size);
 	}
 
 	@RequestMapping("/brandIds")
 	@ResponseBody
 	public SPage<Long> searchBrandIds(@RequestParam String keyword, Integer page, Integer size,
-									  HttpServletRequest request) {
+									  HttpServletRequest request) throws IOException {
 		return searchService.getBrandIds(keyword, page, size);
 	}
 
 	@RequestMapping("/brands")
 	@ResponseBody
 	public SPage<Map<String, Object>> searchBrand(@RequestParam String keyword, Integer page, Integer size,
-												  HttpServletRequest request) {
+												  HttpServletRequest request) throws IOException {
 		return searchService.getBrands(keyword, page, size);
 	}
 
@@ -148,25 +147,25 @@ public class SearchController {
 
 	@RequestMapping("/similarBrands")
 	@ResponseBody
-	public List<Map<String, Object>> getSimilarBrands(@RequestParam String keyword, Integer size, HttpServletRequest request) {
+	public List<Map<String, Object>> getSimilarBrands(@RequestParam String keyword, Integer size, HttpServletRequest request) throws IOException {
 		return searchService.getSimilarBrands(keyword, size);
 	}
 
 	@RequestMapping("/similarKinds")
 	@ResponseBody
-	public List<Map<String, Object>> getSimilarKinds(@RequestParam String keyword, Integer size, HttpServletRequest request) {
+	public List<Map<String, Object>> getSimilarKinds(@RequestParam String keyword, Integer size, HttpServletRequest request) throws IOException {
 		return searchService.getSimilarKinds(keyword, size);
 	}
 
 	@RequestMapping("/similarLeafKinds")
 	@ResponseBody
-	public List<Map<String, Object>> getSimilarLeafKinds(@RequestParam String keyword, Integer size, HttpServletRequest request) {
+	public List<Map<String, Object>> getSimilarLeafKinds(@RequestParam String keyword, Integer size, HttpServletRequest request) throws IOException {
 		return searchService.getSimilarLeafKinds(keyword, size);
 	}
 
 	@RequestMapping("/similarKindsByLevel")
 	@ResponseBody
-	public List<Map<String, Object>> getSimilarKindsByLevel(@RequestParam String keyword, Short level, Integer size, HttpServletRequest request) {
+	public List<Map<String, Object>> getSimilarKindsByLevel(@RequestParam String keyword, Short level, Integer size, HttpServletRequest request) throws IOException {
 		return searchService.getSimilarKindsByLevel(keyword, level, size);
 	}
 
@@ -228,39 +227,39 @@ public class SearchController {
 
 	@RequestMapping("/kind/{id}")
 	@ResponseBody
-	public Kind getKind(@PathVariable Long id, HttpServletRequest request) {
+	public Kind getKind(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return searchService.getKind(id);
 	}
 
 	@RequestMapping("/brand/{id}")
 	@ResponseBody
-	public Brand getBrand(@PathVariable Long id, HttpServletRequest request) {
+	public Brand getBrand(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return searchService.getBrand(id);
 	}
 
 	@RequestMapping("/component/{id}")
 	@ResponseBody
-	public Component getComponent(@PathVariable Long id, HttpServletRequest request) {
+	public Component getComponent(@PathVariable Long id, HttpServletRequest request) throws IOException {
 		return searchService.getComponent(id);
 	}
 
 	@RequestMapping("/goods/{id}")
 	@ResponseBody
-	public Goods getGoods(@PathVariable String id, HttpServletRequest request) {
+	public Goods getGoods(@PathVariable String id, HttpServletRequest request) throws IOException {
 		return searchService.getGoods(id);
 	}
 
 	@RequestMapping("/objects")
 	@ResponseBody
 	public SPage<Object> getObjects(@RequestParam String tableName, String keyword, String field,
-									Boolean tokenized, Integer page, Integer size, HttpServletRequest request) {
+									Boolean tokenized, Integer page, Integer size, HttpServletRequest request) throws IOException {
 		return searchService.getObjects(tableName.toLowerCase(), keyword, field, tokenized, page == null ? 0 : page,
 				size == null ? 0 : size);
 	}
 
 	@RequestMapping("/allObjectsToFiles")
 	@ResponseBody
-	public String writeAllObjectsToFiles(@RequestParam String tableName, HttpServletRequest request) {
+	public String writeAllObjectsToFiles(@RequestParam String tableName, HttpServletRequest request) throws IOException {
 		int page = 1;
 		int size = 1000;
 		// 不能边更新索引边分页获取索引中的数据,因为索引更新后,分页顺序可能也会变化,
@@ -276,39 +275,35 @@ public class SearchController {
 		int fileIndex = 1;
 		PrintWriter printWriter = null;
 		int count = 0;
-		try {
-			File file = new File(SearchUtils.getDataPath(tableName));
-			if (!file.exists()) {
-				file.mkdirs();
-			}
-			printWriter = new PrintWriter(SearchUtils.getDataPath(tableName) + "/" + fileIndex + ".txt");
-			while (true) {
-				// 一个文件存放100000条数据,一旦超过,写入新的文件
-				if (count > IndexServiceImpl.SINGLE_FILE_MAX_SIZE) {
-					count = 1;
-					printWriter.flush();
-					printWriter.close();
-					fileIndex++;
-					printWriter = new PrintWriter(SearchUtils.getDataPath(tableName) + "/" + fileIndex + ".txt");
-				}
-				List<Object> content = sPage.getContent();
-				for (Object element : content) {
-					printWriter.println(JSONObject.toJSONString(element));
-					count++;
-				}
-				logger.info(String.format(tableName + "...................%.2f%%",
-						((page - 1) * size + content.size()) * 100.0 / totalElements));
-
-				if (++page > sPage.getTotalPage()) {
-					break;
-				}
-				sPage = searchService.getObjects(tableName.toLowerCase(), null, null, null, page, size);
-			}
-			printWriter.flush();
-			printWriter.close();
-		} catch (FileNotFoundException | SecurityException | IllegalArgumentException e) {
-			throw new SearchException(e).setDetailedMessage(e);
-		}
+        File file = new File(SearchUtils.getDataPath(tableName));
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+        printWriter = new PrintWriter(SearchUtils.getDataPath(tableName) + "/" + fileIndex + ".txt");
+        while (true) {
+            // 一个文件存放100000条数据,一旦超过,写入新的文件
+            if (count > IndexServiceImpl.SINGLE_FILE_MAX_SIZE) {
+                count = 1;
+                printWriter.flush();
+                printWriter.close();
+                fileIndex++;
+                printWriter = new PrintWriter(SearchUtils.getDataPath(tableName) + "/" + fileIndex + ".txt");
+            }
+            List<Object> content = sPage.getContent();
+            for (Object element : content) {
+                printWriter.println(JSONObject.toJSONString(element));
+                count++;
+            }
+            logger.info(String.format(tableName + "...................%.2f%%",
+                    ((page - 1) * size + content.size()) * 100.0 / totalElements));
+
+            if (++page > sPage.getTotalPage()) {
+                break;
+            }
+            sPage = searchService.getObjects(tableName.toLowerCase(), null, null, null, page, size);
+        }
+        printWriter.flush();
+        printWriter.close();
 		Long endTime = new Date().getTime();
 		String message = String.format("写入数据%s条,耗时%.2fs\n ", totalElements, (endTime - startTime) / 1000.0);
 		logger.info(message);

+ 0 - 90
mall-search/src/main/java/com/uas/search/exception/SearchException.java

@@ -1,90 +0,0 @@
-package com.uas.search.exception;
-
-/**
- * 搜索异常
- * 
- * @author sunyj
- * @since 2016年9月30日 下午3:32:48
- */
-public class SearchException extends RuntimeException {
-
-	private static final long serialVersionUID = 1L;
-
-	private String message;
-
-	/**
-	 * 详细信息
-	 */
-	private String detailedMessage;
-
-	public SearchException(String message) {
-		this.message = message;
-	}
-
-	public SearchException(Throwable e) {
-		this.message = getMessage(e);
-	}
-
-	/**
-	 * 获取异常及其Cause拼接成的字符串
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 拼接后的结果
-	 */
-	public String getMessage(Throwable e) {
-		StringBuilder sb = new StringBuilder(e.toString());
-		if (e.getCause() != null) {
-			sb.append("\nCaused by: ").append(getMessage(e.getCause()));
-		}
-		return sb.toString();
-	}
-
-	/**
-	 * 获取异常及其Cause的StackTrace拼接成的字符串
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 拼接后的结果
-	 */
-	public String getDetailedMessage(Throwable e) {
-		StringBuilder sb = new StringBuilder(e.toString());
-		StackTraceElement[] stackTraceElements = e.getStackTrace();
-		for (StackTraceElement stackTraceElement : stackTraceElements) {
-			sb.append("\n\t").append(stackTraceElement.toString());
-		}
-		if (e.getCause() != null) {
-			sb.append("\nCaused by: ").append(getDetailedMessage(e.getCause()));
-		}
-		return sb.toString();
-	}
-
-	/**
-	 * 获取异常及其Cause的StackTrace用以设置详细信息
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 本SearchException对象
-	 */
-	public SearchException setDetailedMessage(Throwable e) {
-		this.detailedMessage = getDetailedMessage(e);
-		return this;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-
-	public void setMessage(String message) {
-		this.message = message;
-	}
-
-	public String getDetailedMessage() {
-		return detailedMessage;
-	}
-
-	public void setDetailedMessage(String detailedMessage) {
-		this.detailedMessage = detailedMessage;
-	}
-
-}

+ 2 - 1
mall-search/src/main/java/com/uas/search/service/IndexService.java

@@ -4,6 +4,7 @@ import com.uas.search.annotation.NotEmpty;
 import com.uas.search.model.ParsedQueueMessage;
 import com.uas.search.support.DownloadHelper;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -95,5 +96,5 @@ public interface IndexService {
      * @param newWords 词典新词
      * @return 更新的对象
      */
-    Map<String, List<Object>> updateIndexByNewWords(List<String> newWords);
+    Map<String, List<Object>> updateIndexByNewWords(List<String> newWords) throws IOException;
 }

+ 13 - 13
mall-search/src/main/java/com/uas/search/service/OrderSearchService.java

@@ -3,11 +3,12 @@ package com.uas.search.service;
 import com.uas.search.constant.model.BaseOrder;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
-import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Order;
-import com.uas.search.model.PurchaseInvoice;
+import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Purchase;
+import com.uas.search.model.PurchaseInvoice;
+
+import java.io.IOException;
 
 /**
  * 商城订单搜索服务
@@ -110,8 +111,7 @@ public interface OrderSearchService {
 	 *         如果关键词没命中主表信息,命中了从表中的信息,结果有主表带被命中的从表信息;<br>
 	 *         如果都没有命中,则不命中。
 	 */
-	public SPage<BaseOrder> getOrderIdsWithDetail(String keyword, Table_name tableName, PageParams params)
-			throws SearchException;
+	public SPage<BaseOrder> getOrderIdsWithDetail(String keyword, Table_name tableName, PageParams params) throws IOException;
 
 	/**
 	 * 根据关键词和其他信息搜索销售单id信息
@@ -127,7 +127,7 @@ public interface OrderSearchService {
 	 *         如果关键词没命中主表信息,命中了从表中的信息,结果有主表带被命中的从表信息;<br>
 	 *         如果都没有命中,则不命中。
 	 */
-	public SPage<BaseOrder> searchOrderIds(String keyword, PageParams params);
+	public SPage<BaseOrder> searchOrderIds(String keyword, PageParams params) throws IOException;
 
 	/**
 	 * 根据关键词和其他信息搜索销售发货单id信息
@@ -142,7 +142,7 @@ public interface OrderSearchService {
 	 *         如果关键词没命中主表信息,命中了从表中的信息,结果有主表带被命中的从表信息;<br>
 	 *         如果都没有命中,则不命中。
 	 */
-	public SPage<BaseOrder> searchOrderInvoiceIds(String keyword, PageParams params);
+	public SPage<BaseOrder> searchOrderInvoiceIds(String keyword, PageParams params) throws IOException;
 
 	/**
 	 * 根据关键词和其他信息搜索采购单id信息
@@ -157,7 +157,7 @@ public interface OrderSearchService {
 	 *         如果关键词没命中主表信息,命中了从表中的信息,结果有主表带被命中的从表信息;<br>
 	 *         如果都没有命中,则不命中。
 	 */
-	public SPage<BaseOrder> searchPurchaseIds(String keyword, PageParams params);
+	public SPage<BaseOrder> searchPurchaseIds(String keyword, PageParams params) throws IOException;
 
 	/**
 	 * 根据关键词和其他信息搜索采购发货单id信息
@@ -172,7 +172,7 @@ public interface OrderSearchService {
 	 *         如果关键词没命中主表信息,命中了从表中的信息,结果有主表带被命中的从表信息;<br>
 	 *         如果都没有命中,则不命中。
 	 */
-	public SPage<BaseOrder> searchPurchaseInvoiceIds(String keyword, PageParams params);
+	public SPage<BaseOrder> searchPurchaseInvoiceIds(String keyword, PageParams params) throws IOException;
 
 	/**
 	 * 根据id获取索引中的销售单数据
@@ -180,7 +180,7 @@ public interface OrderSearchService {
 	 * @param id
 	 * @return
 	 */
-	public Order getOrder(Long id);
+	public Order getOrder(Long id) throws IOException;
 
 	/**
 	 * 根据id获取索引中的销售发货单数据
@@ -188,7 +188,7 @@ public interface OrderSearchService {
 	 * @param id
 	 * @return
 	 */
-	public OrderInvoice getOrderInvoice(Long id);
+	public OrderInvoice getOrderInvoice(Long id) throws IOException;
 
 	/**
 	 * 根据id获取索引中的采购单数据
@@ -196,7 +196,7 @@ public interface OrderSearchService {
 	 * @param id
 	 * @return
 	 */
-	public Purchase getPurchase(Long id);
+	public Purchase getPurchase(Long id) throws IOException;
 
 	/**
 	 * 根据id获取索引中的采购发货单数据
@@ -204,5 +204,5 @@ public interface OrderSearchService {
 	 * @param id
 	 * @return
 	 */
-	public PurchaseInvoice getPurchaseInvoice(Long id);
+	public PurchaseInvoice getPurchaseInvoice(Long id) throws IOException;
 }

+ 23 - 40
mall-search/src/main/java/com/uas/search/service/SearchService.java

@@ -5,12 +5,12 @@ import com.uas.search.constant.model.CollectField;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.PageParams.FilterField;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
 import com.uas.search.model.Brand;
 import com.uas.search.model.Component;
 import com.uas.search.model.Goods;
 import com.uas.search.model.Kind;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -33,9 +33,8 @@ public interface SearchService {
 	 * @param size
 	 *            页大小
 	 * @return 符合条件的类目id
-	 * @throws SearchException
 	 */
-	public SPage<Long> getKindIds(String keyword, Integer page, Integer size) throws SearchException;
+	public SPage<Long> getKindIds(String keyword, Integer page, Integer size) throws IOException;
 
 	/**
 	 * 根据关键词搜索产品类目
@@ -47,9 +46,8 @@ public interface SearchService {
 	 * @param size
 	 *            页大小
 	 * @return
-	 * @throws SearchException
 	 */
-	public SPage<Map<String, Object>> getKinds(String keyword, Integer page, Integer size) throws SearchException;
+	public SPage<Map<String, Object>> getKinds(String keyword, Integer page, Integer size) throws IOException;
 
 	/**
 	 * 根据关键词搜索产品品牌id
@@ -61,9 +59,8 @@ public interface SearchService {
 	 * @param size
 	 *            页大小
 	 * @return 符合条件的品牌id
-	 * @throws SearchException
 	 */
-	public SPage<Long> getBrandIds(String keyword, Integer page, Integer size) throws SearchException;
+	public SPage<Long> getBrandIds(String keyword, Integer page, Integer size) throws IOException;
 
 	/**
 	 * 根据关键词搜索产品品牌
@@ -75,9 +72,8 @@ public interface SearchService {
 	 * @param size
 	 *            页大小
 	 * @return 符合条件的品牌
-	 * @throws SearchException
 	 */
-	public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) throws SearchException;
+	public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) throws IOException;
 
 	/**
 	 * 根据关键词搜索产品(关键词可能是器件、类目、品牌,甚至可能是类目、品牌的混合)
@@ -129,9 +125,8 @@ public interface SearchService {
 	 *            </table>
 	 * 
 	 * @return
-	 * @throws SearchException
 	 */
-	public Map<String, Object> getComponentIds(String keyword, PageParams params) throws SearchException;
+	public Map<String, Object> getComponentIds(String keyword, PageParams params) ;
 
 	/**
 	 * 根据产品搜索获取产品类目id的统计
@@ -140,9 +135,8 @@ public interface SearchService {
 	 * @param brandId
 	 *            (可选)
 	 * @return
-	 * @throws SearchException
 	 */
-	public Set<Long> getKindIdsBySearchComponent(String keyword, String brandId) throws SearchException;
+	public Set<Long> getKindIdsBySearchComponent(String keyword, String brandId) ;
 
 	/**
 	 * 根据产品搜索获取产品类目的统计
@@ -151,9 +145,8 @@ public interface SearchService {
 	 * @param brandId
 	 *            (可选)
 	 * @return
-	 * @throws SearchException
 	 */
-	public Set<Map<String, Object>> getKindsBySearchComponent(String keyword, String brandId) throws SearchException;
+	public Set<Map<String, Object>> getKindsBySearchComponent(String keyword, String brandId) ;
 
 	/**
 	 * 根据产品搜索获取产品品牌id的统计
@@ -162,9 +155,8 @@ public interface SearchService {
 	 * @param kindId
 	 *            (可选)
 	 * @return
-	 * @throws SearchException
 	 */
-	public Set<Long> getBrandIdsBySearchComponent(String keyword, String kindId) throws SearchException;
+	public Set<Long> getBrandIdsBySearchComponent(String keyword, String kindId) ;
 
 	/**
 	 * 根据产品搜索获取产品品牌的统计
@@ -173,9 +165,8 @@ public interface SearchService {
 	 * @param kindId
 	 *            (可选)
 	 * @return
-	 * @throws SearchException
 	 */
-	public Set<Map<String, Object>> getBrandsBySearchComponent(String keyword, String kindId) throws SearchException;
+	public Set<Map<String, Object>> getBrandsBySearchComponent(String keyword, String kindId) ;
 
 	/**
 	 * 根据输入获取联想词(包括器件、类目、品牌,按顺序获取,数量不足,才会获取下一个)
@@ -183,9 +174,8 @@ public interface SearchService {
 	 * @param keyword
 	 * @param size 指定的联想词数目
 	 * @return
-	 * @throws SearchException
 	 */
-	public List<String> getSimilarKeywords(String keyword, Integer size) throws SearchException;
+	public List<String> getSimilarKeywords(String keyword, Integer size) ;
 
 	/**
 	 * 根据输入的原厂型号获取联想词
@@ -193,9 +183,8 @@ public interface SearchService {
 	 * @param componentCode
 	 * @param size 指定的联想词数目
 	 * @return 包括id、uuid、code
-	 * @throws SearchException
 	 */
-	public List<Map<String, Object>> getSimilarComponents(String componentCode, Integer size) throws SearchException;
+	public List<Map<String, Object>> getSimilarComponents(String componentCode, Integer size) ;
 
 	/**
 	 * 根据输入的品牌获取联想词
@@ -203,9 +192,8 @@ public interface SearchService {
 	 * @param brandName
 	 * @param size 指定的联想词数目
 	 * @return 包括id、uuid、nameCn、nameEn
-	 * @throws SearchException
 	 */
-	public List<Map<String, Object>> getSimilarBrands(String brandName, Integer size) throws SearchException;
+	public List<Map<String, Object>> getSimilarBrands(String brandName, Integer size) throws IOException;
 
 	/**
 	 * 根据输入的类目名获取联想词
@@ -213,9 +201,8 @@ public interface SearchService {
 	 * @param kindName
 	 * @param size 指定的联想词数目
 	 * @return 包括id、nameCn、level、isLeaf
-	 * @throws SearchException
 	 */
-	public List<Map<String, Object>> getSimilarKinds(String kindName, Integer size) throws SearchException;
+	public List<Map<String, Object>> getSimilarKinds(String kindName, Integer size) throws IOException;
 
 	/**
 	 * 根据输入的类目名获取末级类目联想词
@@ -223,9 +210,8 @@ public interface SearchService {
 	 * @param kindName
 	 * @param size 指定的联想词数目
 	 * @return 包括id、nameCn、level、isLeaf
-	 * @throws SearchException
 	 */
-	public List<Map<String, Object>> getSimilarLeafKinds(String kindName, Integer size) throws SearchException;
+	public List<Map<String, Object>> getSimilarLeafKinds(String kindName, Integer size) throws IOException;
 
 	/**
 	 * 根据输入的类目名和指定的类目级别获取联想词
@@ -234,9 +220,8 @@ public interface SearchService {
 	 * @param level
 	 * @param size 指定的联想词数目
 	 * @return 包括id、nameCn、level、isLeaf
-	 * @throws SearchException
 	 */
-	public List<Map<String, Object>> getSimilarKindsByLevel(String kindName, Short level, Integer size) throws SearchException;
+	public List<Map<String, Object>> getSimilarKindsByLevel(String kindName, Short level, Integer size) throws IOException;
 
 	/**
 	 * 根据类目id、属性id、属性值获取联想词
@@ -250,10 +235,8 @@ public interface SearchService {
 	 * @param topNum
 	 *            (可选) 获取的最大数目
 	 * @return 相似的属性值,包括propertyValue
-	 * @throws SearchException
 	 */
-	public List<Map<String, String>> getSimilarPropertyValues(Long kindId, Long propertyId, String keyword, Long topNum)
-			throws SearchException;
+	public List<Map<String, String>> getSimilarPropertyValues(Long kindId, Long propertyId, String keyword, Long topNum);
 
 	/**
 	 * 根据关键词搜索批次(关键词可能是器件、类目、品牌)
@@ -310,7 +293,7 @@ public interface SearchService {
 	 * 
 	 * @return 器件id、批次id和分页信息
 	 */
-	public Map<String, Object> getGoodsIds(String keyword, PageParams pageParams) throws SearchException;
+	public Map<String, Object> getGoodsIds(String keyword, PageParams pageParams) ;
 
 	/**
 	 * 搜索批次时,统计指定信息
@@ -381,7 +364,7 @@ public interface SearchService {
 	 * @param id
 	 * @return
 	 */
-	public Kind getKind(Long id);
+	public Kind getKind(Long id) throws IOException;
 
 	/**
 	 * 根据id获取品牌
@@ -389,7 +372,7 @@ public interface SearchService {
 	 * @param id
 	 * @return
 	 */
-	public Brand getBrand(Long id);
+	public Brand getBrand(Long id) throws IOException;
 
 	/**
 	 * 根据id获取器件
@@ -397,7 +380,7 @@ public interface SearchService {
 	 * @param id
 	 * @return
 	 */
-	public Component getComponent(Long id);
+	public Component getComponent(Long id) throws IOException;
 
 	/**
 	 * 根据id获取批次
@@ -405,7 +388,7 @@ public interface SearchService {
 	 * @param id
 	 * @return
 	 */
-	public Goods getGoods(String id);
+	public Goods getGoods(String id) throws IOException;
 
 	/**
 	 * 分页获取本地指定表的索引中的数据
@@ -424,6 +407,6 @@ public interface SearchService {
 	 *            分页大小
 	 * @return
 	 */
-	public SPage<Object> getObjects(String tableName, String keyword, String field, Boolean tokenized, @NotEmpty("page") Integer page, @NotEmpty("size") Integer size);
+	public SPage<Object> getObjects(String tableName, String keyword, String field, Boolean tokenized, @NotEmpty("page") Integer page, @NotEmpty("size") Integer size) throws IOException;
 
 }

+ 5 - 6
mall-search/src/main/java/com/uas/search/service/impl/IndexServiceImpl.java

@@ -9,7 +9,6 @@ import com.uas.search.constant.model.PageInfo;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.SPage;
 import com.uas.search.dao.*;
-import com.uas.search.exception.SearchException;
 import com.uas.search.jms.JmsListener;
 import com.uas.search.jms.QueueMessageParser;
 import com.uas.search.model.*;
@@ -107,7 +106,7 @@ public class IndexServiceImpl implements IndexService {
 	@Override
 	public Long createIndexes(List<String> tableNames, Boolean componentFromFiles) {
 		if (creatingIndex) {
-			throw new SearchException("已存在线程在创建索引,不可重复请求");
+			throw new IllegalStateException("已存在线程在创建索引,不可重复请求");
 		}
 		creatingIndex = true;
 		// 如果索引实时更新处于开启状态,需要关闭(以免两者同时操作索引出现问题)
@@ -608,7 +607,7 @@ public class IndexServiceImpl implements IndexService {
 						indexWriter.updateDocument(new Term(SearchConstants.PURCHASE_INVOICE_ID_FIELD,
 								String.valueOf(((PurchaseInvoice) obj).getId())), document);
 					} else {
-						throw new SearchException("Message parsing failed!");
+						throw new IllegalStateException("Message parsing failed!");
 					}
 					indexSearcherManager.flushCache(tableName, indexWriter, null);
 					return obj;
@@ -654,7 +653,7 @@ public class IndexServiceImpl implements IndexService {
 					indexWriter.deleteDocuments(new Term(SearchConstants.PURCHASE_INVOICE_ID_FIELD,
 							String.valueOf(((PurchaseInvoice) obj).getId())));
 				} else {
-					throw new SearchException("Message parsing failed!");
+					throw new IllegalStateException("Message parsing failed!");
 				}
 				indexSearcherManager.flushCache(tableName, indexWriter, null);
 				return obj;
@@ -743,7 +742,7 @@ public class IndexServiceImpl implements IndexService {
 	}
 
 	@Override
-	public Map<String, List<Object>> updateIndexByNewWords(List<String> newWords) {
+	public Map<String, List<Object>> updateIndexByNewWords(List<String> newWords) throws IOException {
 		Map<String, List<Object>> updatedObjects = new HashMap<>();
 		// 类目
 		updatedObjects.put(SearchConstants.KIND_TABLE_NAME, updateIndexByNewWords(newWords,
@@ -775,7 +774,7 @@ public class IndexServiceImpl implements IndexService {
      * @param fields    新词可能牵涉到的字段名称
      * @return 更新的对象
      */
-    private List<Object> updateIndexByNewWords(List<String> newWords, String tableName, String idField, String... fields) {
+    private List<Object> updateIndexByNewWords(List<String> newWords, String tableName, String idField, String... fields) throws IOException {
         List<Object> updatedObjects = new ArrayList<>();
         if (!CollectionUtils.isEmpty(newWords)) {
             BooleanQuery booleanQuery = new BooleanQuery();

+ 27 - 47
mall-search/src/main/java/com/uas/search/service/impl/OrderSearchServiceImpl.java

@@ -1,42 +1,26 @@
 package com.uas.search.service.impl;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.NumericRangeQuery;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-import com.uas.search.util.CollectionUtils;
-import com.uas.search.util.StringUtils;
-
 import com.uas.search.constant.SearchConstants;
 import com.uas.search.constant.model.BaseOrder;
 import com.uas.search.constant.model.BaseOrderDetail;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.PageParams.FilterField;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
-import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Order;
-import com.uas.search.model.PurchaseInvoice;
+import com.uas.search.model.OrderInvoice;
 import com.uas.search.model.Purchase;
+import com.uas.search.model.PurchaseInvoice;
 import com.uas.search.service.OrderSearchService;
-import com.uas.search.util.DocumentToObjectUtils;
-import com.uas.search.util.OrderSearchUtils;
-import com.uas.search.util.SearchUtils;
+import com.uas.search.util.*;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.*;
 
 /**
  * 单据搜索实现
@@ -60,7 +44,7 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 	private static Logger logger = LoggerFactory.getLogger(OrderSearchServiceImpl.class);
 
 	@Override
-	public SPage<BaseOrder> getOrderIdsWithDetail(String keyword, Table_name tableName, PageParams params) {
+	public SPage<BaseOrder> getOrderIdsWithDetail(String keyword, Table_name tableName, PageParams params) throws IOException {
 		if (tableName == Table_name.ORDER) {
 			return searchOrderIds(keyword, params);
 		} else if (tableName == Table_name.ORDER_INVOICE) {
@@ -70,26 +54,26 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 		} else if (tableName == Table_name.PURCHASE_INVOICE) {
 			return searchPurchaseInvoiceIds(keyword, params);
 		}
-		throw new SearchException("tableName不合法");
+		throw new IllegalArgumentException("tableName不合法");
 	}
 
 	@Override
-	public SPage<BaseOrder> searchOrderIds(String keyword, PageParams params) {
+	public SPage<BaseOrder> searchOrderIds(String keyword, PageParams params) throws IOException {
 		return searchMainOrder(keyword, params, SearchConstants.ORDER_TABLE_NAME);
 	}
 
 	@Override
-	public SPage<BaseOrder> searchOrderInvoiceIds(String keyword, PageParams params) {
+	public SPage<BaseOrder> searchOrderInvoiceIds(String keyword, PageParams params) throws IOException {
 		return searchMainOrder(keyword, params, SearchConstants.ORDER_INVOICE_TABLE_NAME);
 	}
 
 	@Override
-	public SPage<BaseOrder> searchPurchaseIds(String keyword, PageParams params) {
+	public SPage<BaseOrder> searchPurchaseIds(String keyword, PageParams params) throws IOException {
 		return searchMainOrder(keyword, params, SearchConstants.PURCHASE_TABLE_NAME);
 	}
 
 	@Override
-	public SPage<BaseOrder> searchPurchaseInvoiceIds(String keyword, PageParams params) {
+	public SPage<BaseOrder> searchPurchaseInvoiceIds(String keyword, PageParams params) throws IOException {
 		return searchMainOrder(keyword, params, SearchConstants.PURCHASE_INVOICE_TABLE_NAME);
 	}
 
@@ -104,7 +88,7 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 	 *            主表名
 	 * @return 搜索结果
 	 */
-	private SPage<BaseOrder> searchMainOrder(String keyword, PageParams params, String tableName) {
+	private SPage<BaseOrder> searchMainOrder(String keyword, PageParams params, String tableName) throws IOException {
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 		// 获取该表keyword可以搜索的域
 		List<String> keywordFields = OrderSearchUtils.getKeywordFields(tableName);
@@ -210,7 +194,7 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 					return searchDetails(keyword, params, tableName);
 				} else {
 					if ((sPage.getPage() - 1) * sPage.getSize() >= totalHits) {
-						throw new SearchException("页码过大:元素总数量为" + totalHits);
+						throw new IllegalArgumentException("页码过大:元素总数量为" + totalHits);
 					}
 					topDocs = indexSearcher.searchAfter(previousScoreDocs[previousScoreDocs.length - 1], booleanQuery,
 							sPage.getSize());
@@ -248,8 +232,6 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 				baseOrders.add(baseOrder);
 			}
 			sPage.setContent(baseOrders);
-		} catch (NumberFormatException | IOException e) {
-			throw new SearchException(e).setDetailedMessage(e);
 		} finally {
 			SearchUtils.releaseIndexSearcher(indexSearcher);
 		}
@@ -267,10 +249,10 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 	 *            明细表名
 	 * @return 搜索结果
 	 */
-	private SPage<BaseOrder> searchDetails(String keyword, PageParams params, String tableName) {
+	private SPage<BaseOrder> searchDetails(String keyword, PageParams params, String tableName) throws IOException {
 		// 与主表不同,不允许keyword为空(不允许利用正则表达式获取所有明细索引,原因是正则搜索与分词有冲突)
 		if (SearchUtils.isKeywordInvalid(keyword)) {
-			throw new SearchException("搜索关键词无效:" + keyword);
+			throw new IllegalArgumentException("搜索关键词无效:" + keyword);
 		}
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 
@@ -337,7 +319,7 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 				ScoreDoc[] previousScoreDocs = previousTopDocs.scoreDocs;
 				if (totalHits != 0) {
 					if ((sPage.getPage() - 1) * sPage.getSize() >= totalHits) {
-						throw new SearchException("页码过大:元素总数量为" + totalHits);
+						throw new IllegalArgumentException("页码过大:元素总数量为" + totalHits);
 					}
 					topDocs = indexSearcher.searchAfter(previousScoreDocs[previousScoreDocs.length - 1], booleanQuery,
 							sPage.getSize());
@@ -376,8 +358,6 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 				baseOrders.add(baseOrder);
 			}
 			sPage.setContent(baseOrders);
-		} catch (NumberFormatException | IOException e) {
-			throw new SearchException(e).setDetailedMessage(e);
 		} finally {
 			SearchUtils.releaseIndexSearcher(indexSearcher);
 		}
@@ -385,25 +365,25 @@ public class OrderSearchServiceImpl implements OrderSearchService {
 	}
 
 	@Override
-	public Order getOrder(Long id) {
+	public Order getOrder(Long id) throws IOException {
 		return DocumentToObjectUtils.toOrder(
 				SearchUtils.getDocumentById(SearchConstants.ORDER_TABLE_NAME, SearchConstants.ORDER_ID_FIELD, id));
 	}
 
 	@Override
-	public OrderInvoice getOrderInvoice(Long id) {
+	public OrderInvoice getOrderInvoice(Long id) throws IOException {
 		return DocumentToObjectUtils.toOrderInvoice(SearchUtils
 				.getDocumentById(SearchConstants.ORDER_INVOICE_TABLE_NAME, SearchConstants.ORDER_INVOICE_ID_FIELD, id));
 	}
 
 	@Override
-	public Purchase getPurchase(Long id) {
+	public Purchase getPurchase(Long id) throws IOException {
 		return DocumentToObjectUtils.toPurchase(SearchUtils.getDocumentById(SearchConstants.PURCHASE_TABLE_NAME,
 				SearchConstants.PURCHASE_ID_FIELD, id));
 	}
 
 	@Override
-	public PurchaseInvoice getPurchaseInvoice(Long id) {
+	public PurchaseInvoice getPurchaseInvoice(Long id) throws IOException {
 		return DocumentToObjectUtils.toPurchaseInvoice(SearchUtils.getDocumentById(
 				SearchConstants.PURCHASE_INVOICE_TABLE_NAME, SearchConstants.PURCHASE_INVOICE_ID_FIELD, id));
 	}

+ 32 - 37
mall-search/src/main/java/com/uas/search/service/impl/SearchServiceImpl.java

@@ -7,7 +7,6 @@ import com.uas.search.constant.model.CollectField;
 import com.uas.search.constant.model.PageParams;
 import com.uas.search.constant.model.PageParams.FilterField;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
 import com.uas.search.grouping.DistinctGroupCollector;
 import com.uas.search.grouping.GoodsGroupCollector;
 import com.uas.search.model.*;
@@ -50,7 +49,7 @@ public class SearchServiceImpl implements SearchService {
 	private static Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class);
 
 	@Override
-	public SPage<Long> getKindIds(String keyword, Integer page, Integer size) {
+	public SPage<Long> getKindIds(String keyword, Integer page, Integer size) throws IOException {
 		List<Long> ids = new ArrayList<>();
 		SPage<Document> documents = getKindDocuments(keyword, page, size);;
 		SPage<Long> sPage = new SPage<>(documents.getTotalPage(), documents.getTotalElement(), documents.getPage(),
@@ -63,7 +62,7 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public SPage<Map<String, Object>> getKinds(String keyword, Integer page, Integer size) {
+	public SPage<Map<String, Object>> getKinds(String keyword, Integer page, Integer size) throws IOException {
 		List<Map<String, Object>> kinds = new ArrayList<>();
 		SPage<Document> documents = getKindDocuments(keyword, page, size);
 		SPage<Map<String, Object>> sPage = new SPage<>(documents.getTotalPage(),
@@ -79,9 +78,9 @@ public class SearchServiceImpl implements SearchService {
 		return sPage;
 	}
 
-	private SPage<Document> getKindDocuments(String keyword, Integer page, Integer size){
+	private SPage<Document> getKindDocuments(String keyword, Integer page, Integer size) throws IOException {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
-			throw new SearchException("搜索关键词无效:" + keyword);
+			throw new IllegalArgumentException("搜索关键词无效:" + keyword);
 		}
 		BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
 		logger.info(booleanQuery.toString());
@@ -117,7 +116,7 @@ public class SearchServiceImpl implements SearchService {
     }
 
 	@Override
-	public SPage<Long> getBrandIds(String keyword, Integer page, Integer size) {
+	public SPage<Long> getBrandIds(String keyword, Integer page, Integer size) throws IOException {
 		List<Long> ids = new ArrayList<>();
 		SPage<Document> documents = getBrandDocuments(keyword, page, size);
 		SPage<Long> sPage = new SPage<>(documents.getTotalPage(), documents.getTotalElement(), documents.getPage(),
@@ -130,7 +129,7 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) {
+	public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) throws IOException {
 		List<Map<String, Object>> brands = new ArrayList<>();
 		SPage<Document> documents = getBrandDocuments(keyword, page, size);
 		SPage<Map<String, Object>> sPage = new SPage<Map<String, Object>>(documents.getTotalPage(),
@@ -148,9 +147,9 @@ public class SearchServiceImpl implements SearchService {
 		return sPage;
 	}
 
-	private SPage<Document> getBrandDocuments(String keyword, Integer page, Integer size){
+	private SPage<Document> getBrandDocuments(String keyword, Integer page, Integer size) throws IOException {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
-			throw new SearchException("搜索关键词无效:" + keyword);
+			throw new IllegalArgumentException("搜索关键词无效:" + keyword);
 		}
 		BooleanQuery booleanQuery = new BooleanQuery();
 		booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMECN_FIELD, keyword),
@@ -199,10 +198,9 @@ public class SearchServiceImpl implements SearchService {
 	 * @param kindIds
 	 * @param brandIds
 	 * @return
-	 * @throws SearchException
 	 */
 	private Map<String, Object> getComponentIds(String keyword, PageParams pageParams, List<Long> kindIds,
-			List<Long> brandIds) throws SearchException {
+			List<Long> brandIds) {
 		// 因为器件、属性值的数据量远比类目、品牌大得多,而且器件搜索可能还需进行分页,
 		// 所以涉及器件、属性值的搜索,大都不能像类目和品牌一样直接利用SearchUtils.getDocuments方法
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
@@ -434,7 +432,7 @@ public class SearchServiceImpl implements SearchService {
      */
     private DistinctGroupCollector collectBySearchComponent(String keyword, Query filter, String groupField, DistinctGroupCollector.CollectField... collectFields){
 		if (SearchUtils.isKeywordInvalid(keyword)) {
-			throw new SearchException("搜索关键词无效:" + keyword);
+			throw new IllegalArgumentException("搜索关键词无效:" + keyword);
 		}
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 		try {
@@ -500,7 +498,7 @@ public class SearchServiceImpl implements SearchService {
 	public List<Map<String, Object>> getSimilarComponents(String componentCode, Integer size) {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		if (SearchUtils.isKeywordInvalid(componentCode)) {
-			throw new SearchException("输入无效:" + componentCode);
+			throw new IllegalArgumentException("输入无效:" + componentCode);
 		}
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
@@ -534,10 +532,10 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public List<Map<String, Object>> getSimilarBrands(String brandName, Integer size) {
+	public List<Map<String, Object>> getSimilarBrands(String brandName, Integer size) throws IOException {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		if (SearchUtils.isKeywordInvalid(brandName)) {
-			throw new SearchException("输入无效:" + brandName);
+			throw new IllegalArgumentException("输入无效:" + brandName);
 		}
 		List<Map<String, Object>> brands = new ArrayList<Map<String, Object>>();
 		// 品牌名称带有空格,并且中英文名并无一定顺序,因此对nameCn、nameEn均要搜索
@@ -566,19 +564,19 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public List<Map<String, Object>> getSimilarKinds(String kindName, Integer size) {
+	public List<Map<String, Object>> getSimilarKinds(String kindName, Integer size) throws IOException {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		return getSimilarKinds(kindName, null, null, size);
 	}
 
 	@Override
-	public List<Map<String, Object>> getSimilarLeafKinds(String kindName, Integer size) {
+	public List<Map<String, Object>> getSimilarLeafKinds(String kindName, Integer size) throws IOException {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		return getSimilarKinds(kindName, (short) 1, null, size);
 	}
 
 	@Override
-	public List<Map<String, Object>> getSimilarKindsByLevel(String kindName, Short level, Integer size) {
+	public List<Map<String, Object>> getSimilarKindsByLevel(String kindName, Short level, Integer size) throws IOException {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		return getSimilarKinds(kindName, null, level, size);
 	}
@@ -595,10 +593,10 @@ public class SearchServiceImpl implements SearchService {
 	 * @param size 指定的联想词数目
 	 * @return
 	 */
-	private List<Map<String, Object>> getSimilarKinds(String kindName, Short isLeaf, Short level, Integer size) {
+	private List<Map<String, Object>> getSimilarKinds(String kindName, Short isLeaf, Short level, Integer size) throws IOException {
 		size = size == null || size < 1 ? SIMILAR_NUM : size;
 		if (SearchUtils.isKeywordInvalid(kindName)) {
-			throw new SearchException("输入无效:" + kindName);
+			throw new IllegalArgumentException("输入无效:" + kindName);
 		}
 		List<Map<String, Object>> kinds = new ArrayList<>();
 		BooleanQuery booleanQuery = new BooleanQuery();
@@ -633,7 +631,7 @@ public class SearchServiceImpl implements SearchService {
 	public List<Map<String, String>> getSimilarPropertyValues(Long kindId, Long propertyId, String keyword,
 			Long topNum) {
 		if (kindId == null || propertyId == null) {
-			throw new SearchException("类目id和属性id不能为空");
+			throw new IllegalArgumentException("类目id和属性id不能为空");
 		}
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
@@ -749,7 +747,7 @@ public class SearchServiceImpl implements SearchService {
      */
     private List<String> getSimilarValues(String tableName, String field, String sortField, String keyword, Integer size, boolean usePrefixQuery) {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
-			throw new SearchException("输入无效:" + keyword);
+			throw new IllegalArgumentException("输入无效:" + keyword);
 		}
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 
@@ -818,7 +816,7 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public Map<String, Object> getGoodsIds(String keyword, PageParams pageParams) throws SearchException {
+	public Map<String, Object> getGoodsIds(String keyword, PageParams pageParams) {
 		List<String> keywordFields = new ArrayList<>();
 		// 先根据品牌搜索,品牌不存在再搜索型号等
 		keywordFields.add(SearchConstants.GOODS_BR_NAME_CN_UNTOKENIZED_FIELD);
@@ -840,10 +838,9 @@ public class SearchServiceImpl implements SearchService {
 	 * @param pageParams
 	 * @param recursivelyGet 是否递归获取(逐步降低精度,直到只匹配一个字符)
 	 * @return
-	 * @throws SearchException
 	 */
 	private Map<String, Object> getGoodsIds(String keyword, List<String> keywordFields, Boolean tokenized,
-			PageParams pageParams, Boolean recursivelyGet) throws SearchException {
+			PageParams pageParams, Boolean recursivelyGet) {
 		// 因为器件、属性值的数据量远比类目、品牌大得多,而且器件搜索可能还需进行分页,
 		// 所以涉及器件、属性值的搜索,大都不能像类目和品牌一样直接利用SearchUtils.getDocuments方法
 		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.GOODS_TABLE_NAME);
@@ -1025,7 +1022,7 @@ public class SearchServiceImpl implements SearchService {
         if (sort != null) {
             com.uas.search.constant.model.Sort.Field field = sort.getField();
             if (field == null) {
-                throw new SearchException("排序字段不可为空:" + sort);
+                throw new IllegalArgumentException("排序字段不可为空:" + sort);
             }
             boolean reverse = sort.isReverse();
             if (field == RESERVE) {
@@ -1045,7 +1042,7 @@ public class SearchServiceImpl implements SearchService {
                         sortField(SearchConstants.GOODS_GO_RESERVE_FIELD, Type.DOUBLE, true, Double.MIN_VALUE)
                 ));
             } else {
-                throw new SearchException("不支持该排序方式:" + field);
+                throw new IllegalArgumentException("不支持该排序方式:" + field);
             }
         } else {
             // 默认(综合排序)
@@ -1100,7 +1097,7 @@ public class SearchServiceImpl implements SearchService {
 	private List<Map<String, Object>> collectBySearchGoods(String keyword, List<String> keywordFields,
 			Boolean tokenized, CollectField collectedField, Map<FilterField, Object> filters, Boolean recursivelyGet) {
 		if (collectedField == null && CollectionUtils.isEmpty(filters)) {
-			throw new SearchException("参数不合法:collectedField=" + collectedField + ", filter=" + filters);
+			throw new IllegalArgumentException("参数不合法:collectedField=" + collectedField + ", filter=" + filters);
 		}
 		// 与批次搜索的搜索词保持一致,最终有结果的 keyword 是相同的
 		if(recursivelyGet != null && recursivelyGet){
@@ -1144,7 +1141,7 @@ public class SearchServiceImpl implements SearchService {
 				fieldsToLoad.add(SearchConstants.GOODS_CRNAME_FIELD);
 				break;
 			default:
-				throw new SearchException("不支持该统计字段:" + collectedField);
+				throw new IllegalArgumentException("不支持该统计字段:" + collectedField);
 			}
 			GoodsGroupCollector collector = new GoodsGroupCollector(uniqueField, fieldsToLoad);
 			indexSearcher.search(booleanQuery, collector);
@@ -1258,31 +1255,31 @@ public class SearchServiceImpl implements SearchService {
 	}
 
 	@Override
-	public Kind getKind(Long id) {
+	public Kind getKind(Long id) throws IOException {
 		return DocumentToObjectUtils.toKind(
 				SearchUtils.getDocumentById(SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_ID_FIELD, id));
 	}
 
 	@Override
-	public Brand getBrand(Long id) {
+	public Brand getBrand(Long id) throws IOException {
 		return DocumentToObjectUtils.toBrand(
 				SearchUtils.getDocumentById(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_ID_FIELD, id));
 	}
 
 	@Override
-	public Component getComponent(Long id) {
+	public Component getComponent(Long id) throws IOException {
 		return DocumentToObjectUtils.toComponent(SearchUtils.getDocumentById(SearchConstants.COMPONENT_TABLE_NAME,
 				SearchConstants.COMPONENT_ID_FIELD, id));
 	}
 
 	@Override
-	public Goods getGoods(String id) {
+	public Goods getGoods(String id) throws IOException {
 		return DocumentToObjectUtils.toGoods(
 				SearchUtils.getDocumentById(SearchConstants.GOODS_TABLE_NAME, SearchConstants.GOODS_GO_ID_FIELD, id));
 	}
 
 	@Override
-	public SPage<Object> getObjects(String tableName, String keyword, String field, Boolean tokenized, @NotEmpty("page") Integer page, @NotEmpty("size") Integer size) {
+	public SPage<Object> getObjects(String tableName, String keyword, String field, Boolean tokenized, @NotEmpty("page") Integer page, @NotEmpty("size") Integer size) throws IOException {
 		if (keyword == null) {
 			keyword = "";
 		}
@@ -1321,7 +1318,7 @@ public class SearchServiceImpl implements SearchService {
 				int totalHits = previousTopDocs.totalHits;
 				ScoreDoc[] previousScoreDocs = previousTopDocs.scoreDocs;
 				if ((sPage.getPage() - 1) * sPage.getSize() >= totalHits) {
-					throw new SearchException("页码过大:元素总数量为" + totalHits);
+					throw new IllegalArgumentException("页码过大:元素总数量为" + totalHits);
 				}
 				topDocs = indexSearcher.searchAfter(previousScoreDocs[previousScoreDocs.length - 1], query,
 						sPage.getSize());
@@ -1344,8 +1341,6 @@ public class SearchServiceImpl implements SearchService {
 				content.add(DocumentToObjectUtils.toObject(document, tableName));
 			}
 			sPage.setContent(content);
-		} catch (IOException e) {
-			throw new SearchException(e).setDetailedMessage(e);
 		} finally {
 			SearchUtils.releaseIndexSearcher(indexSearcher);
 		}

+ 1 - 2
mall-search/src/main/java/com/uas/search/util/DocumentToObjectUtils.java

@@ -3,7 +3,6 @@ package com.uas.search.util;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.search.constant.SearchConstants;
 import com.uas.search.constant.model.BaseOrderDetail;
-import com.uas.search.exception.SearchException;
 import com.uas.search.model.*;
 import org.apache.lucene.document.Document;
 
@@ -41,7 +40,7 @@ public class DocumentToObjectUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return toPurchaseInvoice(document);
 		}
-		throw new SearchException("不支持的表:" + tableName);
+		throw new IllegalArgumentException("不支持的表:" + tableName);
 	}
 
 	/**

+ 10 - 11
mall-search/src/main/java/com/uas/search/util/OrderSearchUtils.java

@@ -1,11 +1,10 @@
 package com.uas.search.util;
 
+import com.uas.search.constant.SearchConstants;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import com.uas.search.constant.SearchConstants;
-import com.uas.search.exception.SearchException;
-
 /**
  * 单据搜索相关的工具类
  * 
@@ -39,7 +38,7 @@ public class OrderSearchUtils {
 			keywordFields.add(SearchConstants.PURCHASE_INVOICE_CODE_FIELD);
 			keywordFields.add(SearchConstants.PURCHASE_INVOICE_SELLERENNAME_FIELD);
 		} else {
-			throw new SearchException("表不存在:" + tableName);
+			throw new IllegalArgumentException("表不存在:" + tableName);
 		}
 		return keywordFields;
 	}
@@ -61,7 +60,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_ID_FIELD;
 		} else {
-			throw new SearchException("表不存在:" + tableName);
+			throw new IllegalArgumentException("表不存在:" + tableName);
 		}
 	}
 
@@ -82,7 +81,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_CODE_FIELD;
 		} else {
-			throw new SearchException("表不存在:" + tableName);
+			throw new IllegalArgumentException("表不存在:" + tableName);
 		}
 	}
 
@@ -103,7 +102,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_STATUS_FIELD;
 		} else {
-			throw new SearchException("表不存在:" + tableName);
+			throw new IllegalArgumentException("表不存在:" + tableName);
 		}
 	}
 
@@ -124,7 +123,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_DETAILS_FIELD;
 		} else {
-			throw new SearchException("表不存在:" + tableName);
+			throw new IllegalArgumentException("表不存在:" + tableName);
 		}
 	}
 
@@ -139,7 +138,7 @@ public class OrderSearchUtils {
 		if (tableName.equals(SearchConstants.ORDER_TABLE_NAME)) {
 			return SearchConstants.ORDER_BUYERUU_FIELD;
 		} else {
-			throw new SearchException("表中不存在买方个人uu:" + tableName);
+			throw new IllegalStateException("表中不存在买方个人uu:" + tableName);
 		}
 	}
 
@@ -156,7 +155,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.ORDER_INVOICE_TABLE_NAME)) {
 			return SearchConstants.ORDER_INVOICE_BUYERENUU_FIELD;
 		} else {
-			throw new SearchException("表中不存在买方企业uu:" + tableName);
+			throw new IllegalStateException("表中不存在买方企业uu:" + tableName);
 		}
 	}
 
@@ -175,7 +174,7 @@ public class OrderSearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_SELLERENUU_FIELD;
 		} else {
-			throw new SearchException("表中不存在卖方企业uu:" + tableName);
+			throw new IllegalStateException("表中不存在卖方企业uu:" + tableName);
 		}
 	}
 

+ 13 - 16
mall-search/src/main/java/com/uas/search/util/SearchUtils.java

@@ -4,7 +4,6 @@ import com.uas.search.LuceneProperties;
 import com.uas.search.analyzer.IKAnalyzer;
 import com.uas.search.constant.SearchConstants;
 import com.uas.search.constant.model.SPage;
-import com.uas.search.exception.SearchException;
 import com.uas.search.model.*;
 import com.uas.search.support.IndexSearcherManager;
 import org.apache.lucene.analysis.Analyzer;
@@ -201,7 +200,7 @@ public class SearchUtils {
 	public static IndexSearcher getIndexSearcher(String tableName) {
 		IndexSearcher indexSearcher = searcherManager.get(tableName);
 		if (indexSearcher == null) {
-			throw new SearchException("获取索引文件失败");
+			throw new IllegalStateException("获取索引文件失败");
 		}
 		return indexSearcher;
 	}
@@ -226,9 +225,9 @@ public class SearchUtils {
 	 *            搜索词
 	 * @return Document
 	 */
-	public static Document getDocumentById(String tableName, String field, Long id) {
+	public static Document getDocumentById(String tableName, String field, Long id) throws IOException {
 		if (id == null) {
-			throw new SearchException("输入无效:" + id);
+			throw new IllegalArgumentException("输入无效:" + id);
 		}
 		return getDocumentById(tableName, field, Long.toString(id));
 	}
@@ -244,16 +243,16 @@ public class SearchUtils {
 	 *            搜索词
 	 * @return Document
 	 */
-	public static Document getDocumentById(String tableName, String field, String id) {
+	public static Document getDocumentById(String tableName, String field, String id) throws IOException {
 		if (StringUtils.isEmpty(field) || StringUtils.isEmpty(id)) {
-			throw new SearchException("搜索的域和搜索词不能为空");
+			throw new IllegalArgumentException("搜索的域和搜索词不能为空");
 		}
 		TermQuery termQuery = new TermQuery(new Term(field, id));
 		List<Document> documents = getDocuments(tableName, termQuery).getContent();
 		if (CollectionUtils.isEmpty(documents)) {
 			return null;
 		} else if (documents.size() > 1) {
-			throw new SearchException("索引中存在不止一个对象:" + field + "=" + id);
+			throw new IllegalStateException("索引中存在不止一个对象:" + field + "=" + id);
 		}
 		return documents.get(0);
 	}
@@ -267,7 +266,7 @@ public class SearchUtils {
 	 *            查询条件
 	 * @return
 	 */
-	public static SPage<Document> getDocuments(String tableName, Query query) {
+	public static SPage<Document> getDocuments(String tableName, Query query) throws IOException {
 		return getDocuments(tableName, query, null, null);
 	}
 
@@ -284,7 +283,7 @@ public class SearchUtils {
 	 *            页大小
 	 * @return
 	 */
-	public static SPage<Document> getDocuments(String tableName, Query query, Integer page, Integer size) {
+	public static SPage<Document> getDocuments(String tableName, Query query, Integer page, Integer size) throws IOException {
 		return getDocuments(tableName, query, null, page, size);
 	}
 
@@ -302,9 +301,9 @@ public class SearchUtils {
 	 *            页大小
 	 * @return
 	 */
-	public static SPage<Document> getDocuments(String tableName, Query query, Sort sort, Integer page, Integer size) {
+	public static SPage<Document> getDocuments(String tableName, Query query, Sort sort, Integer page, Integer size) throws IOException {
 		if (query == null) {
-			throw new SearchException("query不能为null");
+			throw new IllegalArgumentException("query不能为null");
 		}
 		SPage<Document> sPage = new SPage<>();
 		if (page != null && page > 0) {
@@ -330,7 +329,7 @@ public class SearchUtils {
 				int totalHits = previousTopDocs.totalHits;
 				ScoreDoc[] previousScoreDocs = previousTopDocs.scoreDocs;
 				if ((sPage.getPage() - 1) * sPage.getSize() >= totalHits) {
-					throw new SearchException("页码过大:元素总数量为" + totalHits);
+					throw new IllegalArgumentException("页码过大:元素总数量为" + totalHits);
 				}
 				topDocs = sort == null ? indexSearcher.searchAfter(previousScoreDocs[previousScoreDocs.length - 1], query, sPage.getSize()) :
 						indexSearcher.searchAfter(previousScoreDocs[previousScoreDocs.length - 1], query, sPage.getSize(), sort);
@@ -354,8 +353,6 @@ public class SearchUtils {
 			}
 
 			sPage.setContent(documents);
-		} catch (IOException e) {
-			throw new SearchException(e).setDetailedMessage(e);
 		} finally {
 			releaseIndexSearcher(indexSearcher);
 		}
@@ -387,7 +384,7 @@ public class SearchUtils {
 		} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
 			return SearchConstants.PURCHASE_INVOICE_ID_FIELD;
 		}
-		throw new SearchException("不支持的表:" + tableName);
+		throw new IllegalArgumentException("不支持的表:" + tableName);
 	}
 
 	/**
@@ -435,7 +432,7 @@ public class SearchUtils {
 		} else if (clazz == PurchaseInvoice.class) {
 			return SearchConstants.PURCHASE_INVOICE_TABLE_NAME;
 		} else {
-			throw new SearchException("该实体类没有对应的需要建立索引的表:" + clazz);
+			throw new IllegalStateException("该实体类没有对应的需要建立索引的表:" + clazz);
 		}
 	}