Browse Source

索引分文件夹存放

sunyj 9 năm trước cách đây
mục cha
commit
59c3622b32

+ 14 - 3
search-console/src/main/java/com/uas/search/console/controller/IndexController.java

@@ -1,7 +1,11 @@
 package com.uas.search.console.controller;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -26,8 +30,15 @@ public class IndexController {
 
 	@RequestMapping("/create")
 	@ResponseBody
-	public String initIndexes() {
-		return "Indexes created success in " + indexService.createIndexs() + " ms.";
+	public String initIndexes(String tableNames) {
+		List<String> tableNameList = new ArrayList<>();
+		if (!StringUtils.isEmpty(tableNames)) {
+			String[] strs = tableNames.split(",");
+			for (String str : strs) {
+				tableNameList.add(str.toLowerCase());
+			}
+		}
+		return String.format("Indexes created success in %.2fs", indexService.createIndexs(tableNameList) / 1000.0);
 	}
 
 	@RequestMapping("/listen/start")
@@ -41,7 +52,7 @@ public class IndexController {
 	public String stopListen() {
 		return aqListener.stop();
 	}
-	
+
 	@RequestMapping("/listen/restart")
 	@ResponseBody
 	public String restartListen(Long waitInterval) {

+ 6 - 2
search-console/src/main/java/com/uas/search/console/service/IndexService.java

@@ -1,5 +1,7 @@
 package com.uas.search.console.service;
 
+import java.util.List;
+
 /**
  * 索引处理
  * 
@@ -9,11 +11,13 @@ package com.uas.search.console.service;
 public interface IndexService {
 
 	/**
-	 * 初始化时,从数据库中得到全部类目、品牌和器件对象,写进索引中
+	 * 创建指定表的索引
 	 * 
+	 * @param tableNames
+	 *            指定的表,默认创建所有表的索引
 	 * @return 创建的索引花费总时间 ms
 	 */
-	public Long createIndexs();
+	public Long createIndexs(List<String> tableNames);
 
 	/**
 	 * 将新对象添加在lucene索引中

+ 64 - 61
search-console/src/main/java/com/uas/search/console/service/impl/IndexServiceImpl.java

@@ -5,7 +5,6 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -13,13 +12,12 @@ import java.util.List;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.store.FSDirectory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import com.alibaba.fastjson.JSONObject;
@@ -46,6 +44,7 @@ import com.uas.search.console.support.IndexWriterManager;
 import com.uas.search.console.util.MergeComponentData;
 import com.uas.search.console.util.ObjectToDocumentUtils;
 import com.uas.search.console.util.SearchConstants;
+import com.uas.search.console.util.SearchUtils;
 import com.uas.search.exception.SearchException;
 
 /**
@@ -55,7 +54,7 @@ import com.uas.search.exception.SearchException;
  * @since 2016年8月5日 下午2:23:22
  */
 @Service
-public class IndexServiceImpl implements IndexService, InitializingBean {
+public class IndexServiceImpl implements IndexService {
 
 	@Autowired
 	private KindSimpleInfoDao kindDao;
@@ -80,9 +79,7 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 
 	private IndexWriter indexWriter;
 
-	private static IndexWriterManager indexWriterManager;
-
-	private FSDirectory directory;
+	private static IndexWriterManager indexWriterManager = new IndexWriterManager();
 
 	@Autowired
 	private AQListener aqListener;
@@ -100,76 +97,80 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 	private static Logger logger = LoggerFactory.getLogger(IndexServiceImpl.class);
 
 	@Override
-	public void afterPropertiesSet() throws Exception {
-		try {
-			directory = FSDirectory.open(Paths.get(luceneProperties.getIndexesDir()));
-			indexWriterManager = new IndexWriterManager(directory);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public Long createIndexs() {
+	public Long createIndexs(List<String> tableNames) {
 		if (creatingIndex) {
 			throw new SearchException("已存在线程在创建索引,不可重复请求");
 		}
 		creatingIndex = true;
-		// 如果索引实时更新处于开启状态,需要暂时关闭(以免两者同时操作索引出现问题)
+		// 如果索引实时更新处于开启状态,需要关闭(以免两者同时操作索引出现问题)
 		if (aqListener.isRunning()) {
 			logger.info("索引实时更新服务正在运行,尝试关闭索引实时更新服务...");
 			aqListener.stop();
 		}
 
+		if (CollectionUtils.isEmpty(tableNames)) {
+			tableNames = SearchUtils.getTableNames();
+		}
+
 		try {
-			indexWriter = indexWriterManager.get();
-			logger.info("正在清理旧索引...");
-			indexWriter.deleteAll();
-			indexWriter.commit();
-			logger.info("旧索引清理完毕");
 			Long startTime = new Date().getTime();
 
-			Long kindSize = createKindIndexs();
-			Long kindTime = new Date().getTime();
-			logger.info("创建类目索引: " + kindSize + "条,耗时 " + (kindTime - startTime) + " ms\n");
-
-			Long brandSize = createBrandIndexs();
-			Long brandTime = new Date().getTime();
-			logger.info("创建品牌索引: " + brandSize + "条,耗时 " + (brandTime - kindTime) + " ms\n");
-
-			Long componentSize = createComponentIndexesWithFiles();
-			Long componentTime = new Date().getTime();
-			logger.info("创建器件索引: " + componentSize + "条,耗时 " + (componentTime - brandTime) + " ms\n");
-
-			Long orderSize = createOrderIndexes();
-			Long orderTime = new Date().getTime();
-			logger.info("创建销售单索引: " + orderSize + "条,耗时 " + (orderTime - componentTime) + " ms\n");
-
-			Long orderInvoiceSize = createOrderInvoiceIndexes();
-			Long orderInvoiceTime = new Date().getTime();
-			logger.info("创建销售发货单索引: " + orderInvoiceSize + "条,耗时 " + (orderInvoiceTime - orderTime) + " ms\n");
-
-			Long purchaseSize = createPurchaseIndexes();
-			Long purchaseTime = new Date().getTime();
-			logger.info("创建采购单索引: " + purchaseSize + "条,耗时 " + (purchaseTime - orderInvoiceTime) + " ms\n");
-
-			Long purchaseInvoiceSize = createPurchaseInvoiceIndexes();
-			Long purchaseInvoiceTime = new Date().getTime();
-			logger.info("创建采购发货单索引: " + purchaseInvoiceSize + "条,耗时 " + (purchaseInvoiceTime - purchaseTime) + " ms\n");
+			for (String tableName : tableNames) {
+				Long start = new Date().getTime();
+				Long size = 0L;
+				deleteIndexs(tableName);
+				if (tableName.equals(SearchConstants.KIND_TABLE_NAME)) {
+					size = createKindIndexs();
+				} else if (tableName.equals(SearchConstants.BRAND_TABLE_NAME)) {
+					size = createBrandIndexs();
+				} else if (tableName.equals(SearchConstants.COMPONENT_TABLE_NAME)) {
+					size = createComponentIndexesWithFiles();
+				} else if (tableName.equals(SearchConstants.ORDER_TABLE_NAME)) {
+					size = createOrderIndexes();
+				} else if (tableName.equals(SearchConstants.ORDER_INVOICE_TABLE_NAME)) {
+					size = createOrderInvoiceIndexes();
+				} else if (tableName.equals(SearchConstants.PURCHASE_TABLE_NAME)) {
+					size = createPurchaseIndexes();
+				} else if (tableName.equals(SearchConstants.PURCHASE_INVOICE_TABLE_NAME)) {
+					size = createPurchaseInvoiceIndexes();
+				} else {
+					logger.error("不支持创建该表索引:" + tableName);
+					continue;
+				}
+				indexWriterManager.release(tableName);
+				Long end = new Date().getTime();
+				logger.info(String.format("创建%s索引: %s条,耗时%.2fs\n ", tableName, size, (end - start) / 1000.0));
+			}
 
-			logger.info("索引创建成功, 共用时间 " + (purchaseInvoiceTime - startTime) + " ms");
-			return purchaseInvoiceTime - startTime;
+			Long endTime = new Date().getTime();
+			logger.info(String.format("索引创建成功, 共用时间%.2fs\n", (endTime - startTime) / 1000.0));
+			return endTime - startTime;
 		} catch (IOException e) {
 			e.printStackTrace();
 		} catch (InterruptedException e) {
 			e.printStackTrace();
 		} finally {
 			creatingIndex = false;
-			indexWriterManager.release();
 		}
 		return null;
 	}
 
+	/**
+	 * 删除指定表的索引
+	 * 
+	 * @param tableName
+	 *            表名
+	 * @throws InterruptedException
+	 * @throws IOException
+	 */
+	private void deleteIndexs(String tableName) throws InterruptedException, IOException {
+		indexWriter = indexWriterManager.get(tableName);
+		logger.info("正在清理旧索引..." + tableName);
+		indexWriter.deleteAll();
+		indexWriter.commit();
+		logger.info("旧索引清理完毕..." + tableName);
+	}
+
 	/**
 	 * 创建类目索引
 	 * 
@@ -348,18 +349,18 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 		if (obj == null) {
 			return;
 		}
-
+		String tableName = SearchUtils.getTableName(obj.getClass());
 		Document document = ObjectToDocumentUtils.toDocument(obj);
 		if (document != null) {
 			try {
-				indexWriter = indexWriterManager.get();
+				indexWriter = indexWriterManager.get(tableName);
 				indexWriter.addDocument(document);
 				indexWriter.commit();
 				logger.info("Saved... " + obj + "\n");
 			} catch (IOException | InterruptedException e) {
 				e.printStackTrace();
 			} finally {
-				indexWriterManager.release();
+				indexWriterManager.release(tableName);
 			}
 		} else {
 			logger.info("对象转为Document时为null:" + obj);
@@ -371,10 +372,11 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 		if (obj == null) {
 			return;
 		}
+		String tableName = SearchUtils.getTableName(obj.getClass());
 		Document document = ObjectToDocumentUtils.toDocument(obj);
 		if (document != null) {
 			try {
-				indexWriter = indexWriterManager.get();
+				indexWriter = indexWriterManager.get(tableName);
 				if (obj instanceof KindSimpleInfo) {
 					indexWriter.updateDocument(
 							new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(((KindSimpleInfo) obj).getId())),
@@ -407,7 +409,7 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 			} catch (IOException | InterruptedException e) {
 				e.printStackTrace();
 			} finally {
-				indexWriterManager.release();
+				indexWriterManager.release(tableName);
 			}
 		} else {
 			logger.info("对象转为Document时为null:" + obj);
@@ -419,8 +421,9 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 		if (obj == null) {
 			return;
 		}
+		String tableName = SearchUtils.getTableName(obj.getClass());
 		try {
-			indexWriter = indexWriterManager.get();
+			indexWriter = indexWriterManager.get(tableName);
 			if (obj instanceof KindSimpleInfo) {
 				indexWriter.deleteDocuments(
 						new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(((KindSimpleInfo) obj).getId())));
@@ -451,7 +454,7 @@ public class IndexServiceImpl implements IndexService, InitializingBean {
 		} catch (InterruptedException e) {
 			e.printStackTrace();
 		} finally {
-			indexWriterManager.release();
+			indexWriterManager.release(tableName);
 		}
 		logger.info("Deleted... " + obj + "\n");
 	}

+ 10 - 8
search-console/src/main/java/com/uas/search/console/service/impl/OrderSearchServiceImpl.java

@@ -109,7 +109,7 @@ public class OrderSearchServiceImpl implements OrderSearchService, InnerOrderSea
 		if (SearchUtils.isKeywordInvalid(keyword)) {
 			throw new SearchException("搜索关键词无效:" + keyword);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 		// 获取该表keyword可以搜索的域
 		List<String> keywordFields = OrderSearchUtils.getKeywordFields(tableName);
 
@@ -278,7 +278,7 @@ public class OrderSearchServiceImpl implements OrderSearchService, InnerOrderSea
 		if (SearchUtils.isKeywordInvalid(keyword)) {
 			throw new SearchException("搜索关键词无效:" + keyword);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 
 		SPage<BaseOrder> sPage = new SPage<>();
 		BooleanQuery booleanQuery = new BooleanQuery();
@@ -370,24 +370,26 @@ public class OrderSearchServiceImpl implements OrderSearchService, InnerOrderSea
 
 	@Override
 	public OrderSimpleInfo getOrder(Long id) {
-		return DocumentToObjectUtils.toOrder(SearchUtils.getDocumentById(SearchConstants.ORDER_ID_FIELD, id));
+		return DocumentToObjectUtils.toOrder(
+				SearchUtils.getDocumentById(SearchConstants.ORDER_TABLE_NAME, SearchConstants.ORDER_ID_FIELD, id));
 	}
 
 	@Override
 	public OrderInvoiceSimpleInfo getOrderInvoice(Long id) {
-		return DocumentToObjectUtils
-				.toOrderInvoice(SearchUtils.getDocumentById(SearchConstants.ORDER_INVOICE_ID_FIELD, id));
+		return DocumentToObjectUtils.toOrderInvoice(SearchUtils
+				.getDocumentById(SearchConstants.ORDER_INVOICE_TABLE_NAME, SearchConstants.ORDER_INVOICE_ID_FIELD, id));
 	}
 
 	@Override
 	public PurchaseSimpleInfo getPurchase(Long id) {
-		return DocumentToObjectUtils.toPurchase(SearchUtils.getDocumentById(SearchConstants.PURCHASE_ID_FIELD, id));
+		return DocumentToObjectUtils.toPurchase(SearchUtils.getDocumentById(SearchConstants.PURCHASE_TABLE_NAME,
+				SearchConstants.PURCHASE_ID_FIELD, id));
 	}
 
 	@Override
 	public PurchaseInvoiceSimpleInfo getPurchaseInvoice(Long id) {
-		return DocumentToObjectUtils
-				.toPurchaseInvoice(SearchUtils.getDocumentById(SearchConstants.PURCHASE_INVOICE_ID_FIELD, id));
+		return DocumentToObjectUtils.toPurchaseInvoice(SearchUtils.getDocumentById(
+				SearchConstants.PURCHASE_INVOICE_TABLE_NAME, SearchConstants.PURCHASE_INVOICE_ID_FIELD, id));
 	}
 
 }

+ 30 - 22
search-console/src/main/java/com/uas/search/console/service/impl/SearchServiceImpl.java

@@ -63,7 +63,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		List<Long> ids = new ArrayList<Long>();
 		BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
 		logger.info(booleanQuery.toString());
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			ids.add(Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
 		}
@@ -78,7 +78,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		List<Map<String, Object>> kinds = new ArrayList<Map<String, Object>>();
 		BooleanQuery booleanQuery = SearchUtils.getBooleanQuery(SearchConstants.KIND_NAMECN_FIELD, keyword);
 		logger.info(booleanQuery.toString());
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			Map<String, Object> kind = new HashMap<String, Object>();
 			kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
@@ -100,7 +100,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMEEN_FIELD, keyword),
 				BooleanClause.Occur.SHOULD);
 		logger.info(booleanQuery.toString());
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			ids.add(Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
 		}
@@ -119,7 +119,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		booleanQuery.add(SearchUtils.getBooleanQuery(SearchConstants.BRAND_NAMEEN_FIELD, keyword),
 				BooleanClause.Occur.SHOULD);
 		logger.info(booleanQuery.toString());
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			Map<String, Object> brand = new HashMap<String, Object>();
 			brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
@@ -135,7 +135,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 	public Map<String, Object> getComponentIds(String keyword, PageParams page) {
 		// 因为器件、属性值的数据量远比类目、品牌大得多,而且器件搜索可能还需进行分页,
 		// 所以涉及器件、属性值的搜索,都不能像类目和品牌一样直接利用SearchUtils.getDocuments方法
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
 		if (page == null) {
 			page = new PageParams();
@@ -261,7 +261,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
 			throw new SearchException("搜索关键词无效:" + keyword);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
 		Set<Long> kindIds = new HashSet<Long>();
 		try {
@@ -312,7 +312,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 			booleanQuery.add(new TermQuery(new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(kindId))),
 					BooleanClause.Occur.SHOULD);
 		}
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			Map<String, Object> kind = new HashMap<String, Object>();
 			kind.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
@@ -327,7 +327,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
 			throw new SearchException("搜索关键词无效:" + keyword);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
 		Set<Long> brandIds = new HashSet<Long>();
 		try {
@@ -378,7 +378,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 			booleanQuery.add(new TermQuery(new Term(SearchConstants.BRAND_ID_FIELD, String.valueOf(brandId))),
 					BooleanClause.Occur.SHOULD);
 		}
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery);
 		for (Document document : documents) {
 			Map<String, Object> brand = new HashMap<String, Object>();
 			brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
@@ -431,7 +431,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		if (SearchUtils.isKeywordInvalid(componentCode)) {
 			throw new SearchException("输入无效:" + componentCode);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
 		List<Map<String, Object>> components = new ArrayList<>();
 		try {
@@ -480,7 +480,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		}
 		logger.info(booleanQuery.toString());
 
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery, SIMILAR_NUM);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.BRAND_TABLE_NAME, booleanQuery,
+				SIMILAR_NUM);
 		for (Document document : documents) {
 			Map<String, Object> brand = new HashMap<>();
 			brand.put("id", Long.parseLong(document.get(SearchConstants.BRAND_ID_FIELD)));
@@ -537,7 +538,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 			}
 		}
 		logger.info(booleanQuery.toString());
-		List<Document> documents = SearchUtils.getDocuments(booleanQuery, SIMILAR_NUM);
+		List<Document> documents = SearchUtils.getDocuments(SearchConstants.KIND_TABLE_NAME, booleanQuery, SIMILAR_NUM);
 		for (Document document : documents) {
 			Map<String, Object> map = new HashMap<>();
 			map.put("id", Long.parseLong(document.get(SearchConstants.KIND_ID_FIELD)));
@@ -555,7 +556,7 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		if (kindId == null || propertyId == null) {
 			throw new SearchException("类目id和属性id不能为空");
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(SearchConstants.COMPONENT_TABLE_NAME);
 
 		String propertyIdString = String.valueOf(propertyId);
 		if (!propertyIdString.startsWith(SearchConstants.COMPONENT_PROPERTY_PREFIX)) {
@@ -615,7 +616,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 	 * @return
 	 */
 	private List<String> getSimilarComponentCodes(String componentCode) {
-		return getSimilarValues(SearchConstants.COMPONENT_CODE_FIELD, componentCode);
+		return getSimilarValues(SearchConstants.COMPONENT_TABLE_NAME, SearchConstants.COMPONENT_CODE_FIELD,
+				componentCode);
 	}
 
 	/**
@@ -626,7 +628,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 	 */
 	private List<String> getSimilarBrandNames(String brandName) {
 		// 获取相似的中文品牌
-		List<String> nameCns = getSimilarValues(SearchConstants.BRAND_NAMECN_FIELD, brandName);
+		List<String> nameCns = getSimilarValues(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_NAMECN_FIELD,
+				brandName);
 		// 相似的中文品牌数量足够,直接返回
 		if (nameCns != null && nameCns.size() == SIMILAR_NUM) {
 			return nameCns;
@@ -638,7 +641,8 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 		}
 
 		// 获取相似的英文品牌
-		List<String> nameEns = getSimilarValues(SearchConstants.BRAND_NAMEEN_FIELD, brandName);
+		List<String> nameEns = getSimilarValues(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_NAMEEN_FIELD,
+				brandName);
 		if (CollectionUtils.isEmpty(nameEns)) {
 			return names;
 		}
@@ -660,21 +664,22 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 	 * @return
 	 */
 	private List<String> getSimilarKindNames(String kindName) {
-		return getSimilarValues(SearchConstants.KIND_NAMECN_FIELD, kindName);
+		return getSimilarValues(SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_NAMECN_FIELD, kindName);
 	}
 
 	/**
 	 * 根据输入值获取该域相似的值
 	 * 
+	 * @param tableName
 	 * @param field
 	 * @param keyword
 	 * @return
 	 */
-	private List<String> getSimilarValues(String field, String keyword) {
+	private List<String> getSimilarValues(String tableName, String field, String keyword) {
 		if (SearchUtils.isKeywordInvalid(keyword)) {
 			throw new SearchException("输入无效:" + keyword);
 		}
-		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher();
+		IndexSearcher indexSearcher = SearchUtils.getIndexSearcher(tableName);
 
 		List<String> result = new ArrayList<>();
 		try {
@@ -714,17 +719,20 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 
 	@Override
 	public KindSimpleInfo getKind(Long id) {
-		return DocumentToObjectUtils.toKind(SearchUtils.getDocumentById(SearchConstants.KIND_ID_FIELD, id));
+		return DocumentToObjectUtils.toKind(
+				SearchUtils.getDocumentById(SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_ID_FIELD, id));
 	}
 
 	@Override
 	public BrandSimpleInfo getBrand(Long id) {
-		return DocumentToObjectUtils.toBrand(SearchUtils.getDocumentById(SearchConstants.BRAND_ID_FIELD, id));
+		return DocumentToObjectUtils.toBrand(
+				SearchUtils.getDocumentById(SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_ID_FIELD, id));
 	}
 
 	@Override
 	public ComponentSimpleInfo getComponent(Long id) {
-		return DocumentToObjectUtils.toComponent(SearchUtils.getDocumentById(SearchConstants.COMPONENT_ID_FIELD, id));
+		return DocumentToObjectUtils.toComponent(SearchUtils.getDocumentById(SearchConstants.COMPONENT_TABLE_NAME,
+				SearchConstants.COMPONENT_ID_FIELD, id));
 	}
 
 }

+ 84 - 60
search-console/src/main/java/com/uas/search/console/support/IndexSearcherManager.java

@@ -3,7 +3,11 @@ package com.uas.search.console.support;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.IndexSearcher;
@@ -12,8 +16,7 @@ import org.apache.lucene.store.NIOFSDirectory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.uas.search.console.LuceneProperties;
-import com.uas.search.console.core.util.ContextUtils;
+import com.uas.search.console.util.SearchUtils;
 
 /**
  * 将索引加入缓存,对IndexSearcher进行管理
@@ -23,113 +26,132 @@ import com.uas.search.console.core.util.ContextUtils;
  */
 public class IndexSearcherManager {
 
-	private IndexSearcher currentSearcher;
+	/**
+	 * 用于存放指定表的索引IndexSearcher
+	 */
+	private Map<String, IndexSearcher> indexSearchers = new ConcurrentHashMap<>();
 
-	private FSDirectory directory;
+	/**
+	 * 标识指定表的IndexSearcher是否正在重新打开
+	 */
+	private Map<String, Boolean> reopening = new ConcurrentHashMap<>();
 
 	private static Logger logger = LoggerFactory.getLogger(IndexSearcherManager.class);
 
 	public IndexSearcherManager() {
-		LuceneProperties luceneProperties = ContextUtils.getBean(LuceneProperties.class);
-		try {
-			String os = System.getProperty("os.name");
-			// 本来NIOFSDirectory速度更快,但因为jre的bug,在Windows平台上,其性能很差
-			if (os.toLowerCase().startsWith("win")) {
-				directory = FSDirectory.open(Paths.get(luceneProperties.getIndexesDir()));
-			} else {
-				directory = NIOFSDirectory.open(Paths.get(luceneProperties.getIndexesDir()));
-			}
-			warm();
-		} catch (IOException e) {
-			e.printStackTrace();
+		List<String> tableNames = SearchUtils.getTableNames();
+		for (String tableName : tableNames) {
+			reopening.put(tableName, false);
 		}
 	}
 
-	public IndexSearcherManager(FSDirectory dir) {
-		directory = dir;
-		warm();
-	}
-
 	/**
-	 * 对currentSearcher进行初始化操作
+	 * 对指定表的IndexSearcher进行初始化操作
 	 * 
-	 * @throws IOException
+	 * @param tableName
+	 *            表名
+	 * @return 指定表的FSDirectory
 	 */
-	public synchronized void warm() {
-		File[] files = directory.getDirectory().toFile().listFiles();
-		// 不为空的话说明索引已成功加载
-		if (currentSearcher == null) {
-			// 路径不为空文件夹
-			if (files.length != 0) {
-				try {
-					currentSearcher = new IndexSearcher(DirectoryReader.open(directory));
-				} catch (IOException e) {
-					e.printStackTrace();
-				}
+	private synchronized FSDirectory warm(String tableName) {
+		String indexPath = SearchUtils.getIndexPath(tableName);
+		FSDirectory directory = null;
+		IndexSearcher indexSearcher = indexSearchers.get(tableName);
+		// 本来NIOFSDirectory速度更快,但因为jre的bug,在Windows平台上,其性能很差
+		try {
+			if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
+				directory = FSDirectory.open(Paths.get(indexPath));
 			} else {
-				logger.error("索引文件不存在!");
+				directory = NIOFSDirectory.open(Paths.get(indexPath));
+			}
+
+			File[] files = directory.getDirectory().toFile().listFiles();
+			// 不为空的话说明索引已成功加载
+			if (indexSearcher == null) {
+				// 路径不为空文件夹
+				if (files.length != 0) {
+					try {
+						indexSearcher = new IndexSearcher(DirectoryReader.open(directory));
+						indexSearchers.put(tableName, indexSearcher);
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+				} else {
+					logger.error("索引文件不存在:" + tableName);
+				}
 			}
+		} catch (IOException e) {
+			logger.error("索引路径打开失败:" + indexPath);
+			e.printStackTrace();
 		}
+		return directory;
 	}
 
 	/**
-	 * 内存中IndexReader(可能)更新,根据版本号确定是否更新
+	 * 内存中指定表的IndexReader(可能需要)更新,根据版本号确定是否更新
 	 * 
-	 * @throws InterruptedException
-	 * @throws IOException
+	 * @param tableName
+	 *            表名
 	 */
-	public void maybeReopen() {
-		startReopen();
+	public void maybeReopen(String tableName) {
+		if (StringUtils.isEmpty(tableName)) {
+			return;
+		}
+		startReopen(tableName);
 
 		try {
 			// 每次都要进行初始化处理,是为了防止加载索引时,索引为空,而后来索引不为空时,却不能够正确加载
-			warm();
+			FSDirectory directory = warm(tableName);
+			IndexSearcher currentSearcher = indexSearchers.get(tableName);
 			if (currentSearcher == null) {
 				return;
 			}
-			IndexSearcher searcher = get();
+			IndexSearcher searcher = get(tableName);
 			Long currentVersion = ((DirectoryReader) searcher.getIndexReader()).getVersion();
 			// 版本号不一致(本地索引有更改),更新IndexReader
 			try {
 				if (DirectoryReader.open(directory).getVersion() != currentVersion) {
 					IndexReader newReader = DirectoryReader.open(directory);
 					IndexSearcher newSearcher = new IndexSearcher(newReader);
-					swapIndexSearcher(newSearcher);
+					updateIndexSearcher(tableName, newSearcher);
 				}
 			} catch (IOException e) {
 				e.printStackTrace();
 			}
 			release(searcher);
 		} finally {
-			doneReopen();
+			doneReopen(tableName);
 		}
 
 	}
 
-	private boolean reopening = false;
-
-	private synchronized void startReopen() {
-		while (reopening) {
+	private synchronized void startReopen(String tableName) {
+		while (reopening.get(tableName)) {
 			try {
 				wait();
 			} catch (InterruptedException e) {
 				e.printStackTrace();
 			}
 		}
-		reopening = true;
+		reopening.put(tableName, true);
 	}
 
-	private synchronized void doneReopen() {
-		reopening = false;
+	private synchronized void doneReopen(String tableName) {
+		reopening.put(tableName, false);
 		notifyAll();
 	}
 
 	/**
-	 * 得到IndexSearcher
+	 * 得到指定表的IndexSearcher
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @return
 	 */
-	public synchronized IndexSearcher get() {
+	public synchronized IndexSearcher get(String tableName) {
+		if (StringUtils.isEmpty(tableName)) {
+			return null;
+		}
+		IndexSearcher currentSearcher = indexSearchers.get(tableName);
 		if (currentSearcher != null) {
 			currentSearcher.getIndexReader().incRef();
 		}
@@ -137,14 +159,14 @@ public class IndexSearcherManager {
 	}
 
 	/**
-	 * 释放indexSearcher,将对indexReader的引用减1,为0时成为垃圾
+	 * 释放indexSearcher
 	 * 
 	 * @param indexSearcher
-	 * @throws IOException
 	 */
 	public synchronized void release(IndexSearcher indexSearcher) {
 		if (indexSearcher != null) {
 			try {
+				// 对indexReader的引用减1,为0时成为垃圾
 				indexSearcher.getIndexReader().decRef();
 			} catch (IOException e) {
 				e.printStackTrace();
@@ -153,14 +175,16 @@ public class IndexSearcherManager {
 	}
 
 	/**
-	 * 更新IndexSearcher
+	 * 更新指定表的IndexSearcher
 	 * 
-	 * @param indexSearcher
+	 * @param tableName
+	 *            表名
+	 * @param newIndexSearcher
 	 *            新IndexSearcher
-	 * @throws IOException
 	 */
-	private synchronized void swapIndexSearcher(IndexSearcher indexSearcher) {
+	private synchronized void updateIndexSearcher(String tableName, IndexSearcher newIndexSearcher) {
+		IndexSearcher currentSearcher = indexSearchers.get(tableName);
 		release(currentSearcher);
-		currentSearcher = indexSearcher;
+		indexSearchers.put(tableName, newIndexSearcher);
 	}
 }

+ 73 - 24
search-console/src/main/java/com/uas/search/console/support/IndexWriterManager.java

@@ -1,12 +1,21 @@
 package com.uas.search.console.support;
 
 import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.NIOFSDirectory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wltea.analyzer.lucene.IKAnalyzer;
 
-import com.uas.search.console.util.SearchConstants;
+import com.uas.search.console.util.SearchUtils;
 
 /**
  * 对IndexWriter进行管理,防止同时有多个方法对索引进行修改,抛出LockObtainFailedException异常
@@ -16,51 +25,91 @@ import com.uas.search.console.util.SearchConstants;
  */
 public class IndexWriterManager {
 
-	private IndexWriter indexWriter;
+	/**
+	 * 用于存放指定表的索引IndexWriter
+	 */
+	private Map<String, IndexWriter> indexWriters = new ConcurrentHashMap<>();
+
+	/**
+	 * 标识指定表的索引是否正在使用
+	 */
+	private Map<String, Boolean> using = new ConcurrentHashMap<>();
 
-	private FSDirectory directory;
+	private static Logger logger = LoggerFactory.getLogger(IndexWriterManager.class);
 
-	public IndexWriterManager(FSDirectory dir) {
-		directory = dir;
+	public IndexWriterManager() {
+		List<String> tableNames = SearchUtils.getTableNames();
+		for (String tableName : tableNames) {
+			using.put(tableName, false);
+		}
 	}
 
 	/**
-	 * 得到IndexWriter,用完后需调用release释放IndexWriter
+	 * 得到指定表的IndexWriter,用完后需调用release释放IndexWriter
 	 * 
-	 * @return
-	 * @throws IOException
+	 * @param tableName
+	 *            表名
+	 * @return IndexWriter
 	 * @throws InterruptedException
 	 */
-	public synchronized IndexWriter get() throws IOException, InterruptedException {
-		startUsing();
+	public synchronized IndexWriter get(String tableName) throws InterruptedException {
+		if (StringUtils.isEmpty(tableName)) {
+			return null;
+		}
+		startUsing(tableName);
+		IndexWriter indexWriter = indexWriters.get(tableName);
 		if (indexWriter == null) {
-			IndexWriterConfig config = new IndexWriterConfig(SearchConstants.IK_ANALYZER);// 此处用IK
-			indexWriter = new IndexWriter(directory, config);
+			// 此处用IK
+			IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer());
+			// 获取表对应的索引目录
+			String indexPath = SearchUtils.getIndexPath(tableName);
+			try {
+				FSDirectory directory = null;
+				// 本来NIOFSDirectory速度更快,但因为jre的bug,在Windows平台上,其性能很差
+				if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
+					directory = FSDirectory.open(Paths.get(indexPath));
+				} else {
+					directory = NIOFSDirectory.open(Paths.get(indexPath));
+				}
+				indexWriter = new IndexWriter(directory, config);
+				indexWriters.put(tableName, indexWriter);
+				return indexWriter;
+			} catch (IOException e) {
+				logger.error("索引路径打开失败:" + indexPath);
+				e.printStackTrace();
+				return null;
+			}
+		} else {
+			return indexWriter;
 		}
-		return indexWriter;
 	}
 
 	/**
-	 * 释放对indexWriter的使用
+	 * 释放对指定表的indexWriter的使用
+	 * 
+	 * @param tableName
+	 *            表名
 	 */
-	public synchronized void release() {
+	public synchronized void release(String tableName) {
+		if (StringUtils.isEmpty(tableName)) {
+			throw new NullPointerException("参数不能为空:tableName");
+		}
 		// indexWriter一直保持打开状态,也只存在一个实例,
 		// indexWriter用完后只是释放对其的占用,不会进行close
 		// TODO close方法有时会卡住(多出现在插入记录之后),暂时还未找到原因
-		doneUsing();
+		doneUsing(tableName);
 	}
 
-	private boolean using = false;
-
-	private synchronized void startUsing() throws InterruptedException {
-		while (using) {
+	private synchronized void startUsing(String tableName) throws InterruptedException {
+		while (using.get(tableName)) {
 			wait();
 		}
-		using = true;
+		using.put(tableName, true);
 	}
 
-	private synchronized void doneUsing() {
-		using = false;
+	private synchronized void doneUsing(String tableName) {
+		using.put(tableName, false);
 		notifyAll();
 	}
-}
+
+}

+ 0 - 13
search-console/src/main/java/com/uas/search/console/util/SearchConstants.java

@@ -1,9 +1,5 @@
 package com.uas.search.console.util;
 
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.wltea.analyzer.lucene.IKAnalyzer;
-
 /**
  * 索引相关的常量
  * 
@@ -12,15 +8,6 @@ import org.wltea.analyzer.lucene.IKAnalyzer;
  */
 public class SearchConstants {
 
-	/**
-	 * IK分词解析器
-	 */
-	public static final Analyzer IK_ANALYZER = new IKAnalyzer();
-	/**
-	 * 标准分词解析器
-	 */
-	public static final Analyzer STANDARD_ANALYZER = new StandardAnalyzer();
-
 	/**
 	 * 默认搜索的最大的记录条数
 	 */

+ 102 - 19
search-console/src/main/java/com/uas/search/console/util/SearchUtils.java

@@ -21,6 +21,15 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import org.wltea.analyzer.lucene.IKAnalyzer;
 
+import com.uas.search.console.LuceneProperties;
+import com.uas.search.console.core.util.ContextUtils;
+import com.uas.search.console.model.BrandSimpleInfo;
+import com.uas.search.console.model.ComponentSimpleInfo;
+import com.uas.search.console.model.KindSimpleInfo;
+import com.uas.search.console.model.OrderInvoiceSimpleInfo;
+import com.uas.search.console.model.OrderSimpleInfo;
+import com.uas.search.console.model.PurchaseInvoiceSimpleInfo;
+import com.uas.search.console.model.PurchaseSimpleInfo;
 import com.uas.search.console.support.IndexSearcherManager;
 import com.uas.search.exception.SearchException;
 
@@ -37,6 +46,8 @@ public class SearchUtils {
 	 */
 	private static IndexSearcherManager searcherManager = new IndexSearcherManager();
 
+	private static LuceneProperties luceneProperties = ContextUtils.getBean(LuceneProperties.class);
+
 	/**
 	 * 判断搜索词是否为无效的(比如只包含特殊字符,不含有任何字母、数字、汉字等有意义的字符)
 	 * 
@@ -83,13 +94,15 @@ public class SearchUtils {
 	}
 
 	/**
-	 * 获取IndexSearcher对象,若为空,抛出异常
+	 * 获取指定表的IndexSearcher对象,若为空,抛出异常
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @return IndexSearcher对象
 	 */
-	public static IndexSearcher getIndexSearcher() {
-		searcherManager.maybeReopen();
-		IndexSearcher indexSearcher = searcherManager.get();
+	public static IndexSearcher getIndexSearcher(String tableName) {
+		searcherManager.maybeReopen(tableName);
+		IndexSearcher indexSearcher = searcherManager.get(tableName);
 		if (indexSearcher == null) {
 			throw new SearchException("获取索引文件失败");
 		}
@@ -106,19 +119,21 @@ public class SearchUtils {
 	}
 
 	/**
-	 * 根据域和搜索词获取Document(每个id最多只能对应一条数据)
+	 * 根据域和搜索词获取指定表的Document(每个id最多只能对应一条数据)
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @param field
 	 *            搜索域
 	 * @param keyword
 	 *            搜索词
 	 * @return Document
 	 */
-	public static Document getDocumentById(String field, Long id) {
+	public static Document getDocumentById(String tableName, String field, Long id) {
 		if (id == null) {
 			throw new SearchException("输入无效:" + id);
 		}
-		List<Document> documents = getDocuments(field, Long.toString(id));
+		List<Document> documents = getDocuments(tableName, field, Long.toString(id));
 		if (CollectionUtils.isEmpty(documents)) {
 			return null;
 		} else if (documents.size() > 1) {
@@ -128,21 +143,25 @@ public class SearchUtils {
 	}
 
 	/**
-	 * 根据域和搜索词获取Document列表
+	 * 根据域和搜索词获取指定表的Document列表
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @param field
 	 *            搜索域
 	 * @param keyword
 	 *            搜索词
 	 * @return Document列表
 	 */
-	public static List<Document> getDocuments(String field, String keyword) {
-		return getDocuments(field, keyword, SearchConstants.TOP_NUM);
+	public static List<Document> getDocuments(String tableName, String field, String keyword) {
+		return getDocuments(tableName, field, keyword, SearchConstants.TOP_NUM);
 	}
 
 	/**
-	 * 根据域和搜索词获取指定数目的Document列表
+	 * 根据域和搜索词获取指定数目的指定表的Document列表
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @param field
 	 *            搜索域
 	 * @param keyword
@@ -151,42 +170,46 @@ public class SearchUtils {
 	 *            指定的数目(数目最多为该数目)
 	 * @return
 	 */
-	public static List<Document> getDocuments(String field, String keyword, int topNum) {
+	public static List<Document> getDocuments(String tableName, String field, String keyword, int topNum) {
 		if (StringUtils.isEmpty(field) || StringUtils.isEmpty(keyword)) {
 			throw new SearchException("搜索的域和搜索词不能为空");
 		}
 		TermQuery termQuery = new TermQuery(new Term(field, keyword));
-		return getDocuments(termQuery, topNum);
+		return getDocuments(tableName, termQuery, topNum);
 	}
 
 	/**
-	 * 根据查询条件获取Document列表
+	 * 根据查询条件获取指定表的Document列表
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @param query
 	 *            查询条件
 	 * @return
 	 */
-	public static List<Document> getDocuments(Query query) {
-		return getDocuments(query, SearchConstants.TOP_NUM);
+	public static List<Document> getDocuments(String tableName, Query query) {
+		return getDocuments(tableName, query, SearchConstants.TOP_NUM);
 	}
 
 	/**
-	 * 根据查询条件获取指定数目的Document列表
+	 * 根据查询条件获取指定数目的指定表的Document列表
 	 * 
+	 * @param tableName
+	 *            表名
 	 * @param query
 	 *            查询条件
 	 * @param topNum
 	 *            指定的数目(数目最多为该数目)
 	 * @return
 	 */
-	public static List<Document> getDocuments(Query query, int topNum) {
+	public static List<Document> getDocuments(String tableName, Query query, int topNum) {
 		if (query == null) {
 			throw new SearchException("query不能为null");
 		}
 		if (topNum < 1) {
 			throw new SearchException("查询的数目topNum不能小于1");
 		}
-		IndexSearcher indexSearcher = getIndexSearcher();
+		IndexSearcher indexSearcher = getIndexSearcher(tableName);
 		List<Document> documents = new ArrayList<>();
 		try {
 			TopDocs topDocs = indexSearcher.search(query, topNum);
@@ -201,4 +224,64 @@ public class SearchUtils {
 		}
 		return documents;
 	}
+
+	/**
+	 * 获取所有需要建立索引的表名
+	 * 
+	 * @return
+	 */
+	public static List<String> getTableNames() {
+		List<String> tableNames = new ArrayList<>();
+		tableNames.add(SearchConstants.KIND_TABLE_NAME);
+		tableNames.add(SearchConstants.BRAND_TABLE_NAME);
+		tableNames.add(SearchConstants.COMPONENT_TABLE_NAME);
+		tableNames.add(SearchConstants.ORDER_TABLE_NAME);
+		tableNames.add(SearchConstants.ORDER_INVOICE_TABLE_NAME);
+		tableNames.add(SearchConstants.PURCHASE_TABLE_NAME);
+		tableNames.add(SearchConstants.PURCHASE_INVOICE_TABLE_NAME);
+		return tableNames;
+	}
+
+	/**
+	 * 获取指定的实体类对应的需要建立索引的表名
+	 * 
+	 * @param clazz
+	 * @return
+	 */
+	public static String getTableName(Class<?> clazz) {
+		if (clazz == null) {
+			return null;
+		}
+		if (clazz == KindSimpleInfo.class) {
+			return SearchConstants.KIND_TABLE_NAME;
+		} else if (clazz == BrandSimpleInfo.class) {
+			return SearchConstants.BRAND_TABLE_NAME;
+		} else if (clazz == ComponentSimpleInfo.class) {
+			return SearchConstants.COMPONENT_TABLE_NAME;
+		} else if (clazz == OrderSimpleInfo.class) {
+			return SearchConstants.ORDER_TABLE_NAME;
+		} else if (clazz == OrderInvoiceSimpleInfo.class) {
+			return SearchConstants.ORDER_INVOICE_TABLE_NAME;
+		} else if (clazz == PurchaseSimpleInfo.class) {
+			return SearchConstants.PURCHASE_TABLE_NAME;
+		} else if (clazz == PurchaseInvoiceSimpleInfo.class) {
+			return SearchConstants.PURCHASE_INVOICE_TABLE_NAME;
+		} else {
+			throw new SearchException("该实体类没有对应的需要建立索引的表:" + clazz);
+		}
+	}
+
+	/**
+	 * 获取指定表的索引路径
+	 * 
+	 * @param tableName
+	 *            指定表
+	 * @return 索引路径
+	 */
+	public static String getIndexPath(String tableName) {
+		if (tableName == null) {
+			return null;
+		}
+		return luceneProperties.getIndexesDir() + "/" + tableName;
+	}
 }

+ 1 - 0
search-console/src/main/webapp/WEB-INF/views/console.html

@@ -78,6 +78,7 @@
 				<h2>3. 索引修改</h2>
 				<ol>
 					<li><a target="_blank">index/create</a></li>
+					<li><a target="_blank">index/create?tableNames=product$brand,trade$order</a></li>
 					<li><a target="_blank">index/listen/start?waitInterval=10</a></li>
 					<li><a target="_blank">index/listen/stop</a></li>
 					<li><a target="_blank">index/listen/restart</a></li>