Browse Source

数据文件统一放在data下,与indexes平级

sunyj 8 năm trước cách đây
mục cha
commit
5ee8a996cb

+ 8 - 22
search-console/src/main/java/com/uas/search/console/LuceneProperties.java

@@ -9,14 +9,11 @@ public class LuceneProperties {
 	@Value("${lucene.indexes.dir}")
 	private String indexesDir;
 
-	@Value("${lucene.components.dir}")
-	private String componentsDir;
-
-	@Value("${lucene.goods.dir}")
-	private String goodsDir;
+	@Value("${lucene.data.dir}")
+	private String dataDir;
 
 	/**
-	 * 索引文件存储路径
+	 * @return 索引文件存储路径
 	 */
 	public String getIndexesDir() {
 		return indexesDir;
@@ -27,25 +24,14 @@ public class LuceneProperties {
 	}
 
 	/**
-	 * 存放带有属性的器件数据的文件,用于创建索引
-	 */
-	public String getComponentsDir() {
-		return componentsDir;
-	}
-
-	public void setComponentsDir(String componentsDir) {
-		this.componentsDir = componentsDir;
-	}
-
-	/**
-	 * 存放批次数据的文件,用于创建索引
+	 * @return 存放批次数据的文件,用于创建索引
 	 */
-	public String getGoodsDir() {
-		return goodsDir;
+	public String getDataDir() {
+		return dataDir;
 	}
 
-	public void setGoodsDir(String goodsDir) {
-		this.goodsDir = goodsDir;
+	public void setDataDir(String dataDir) {
+		this.dataDir = dataDir;
 	}
 
 }

+ 7 - 9
search-console/src/main/java/com/uas/search/console/service/impl/IndexServiceImpl.java

@@ -27,7 +27,6 @@ import org.springframework.util.StringUtils;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
-import com.uas.search.console.LuceneProperties;
 import com.uas.search.console.dao.BrandSimpleInfoDao;
 import com.uas.search.console.dao.ComponentSimpleInfoDao;
 import com.uas.search.console.dao.GoodsSimpleInfoDao;
@@ -104,9 +103,6 @@ public class IndexServiceImpl implements IndexService {
 	@Autowired
 	private AQListener aqListener;
 
-	@Autowired
-	private LuceneProperties luceneProperties;
-
 	private IndexSearcherManager indexSearcherManager = IndexSearcherManager.getInstance();
 
 	/**
@@ -237,7 +233,8 @@ public class IndexServiceImpl implements IndexService {
 		Long size = 0L;
 		try {
 			// 从本地路径读取器件数据
-			File[] files = new File(luceneProperties.getComponentsDir()).listFiles();
+			String componentDataPath = SearchUtils.getDataPath(SearchConstants.COMPONENT_TABLE_NAME);
+			File[] files = new File(componentDataPath).listFiles();
 			if (files == null || files.length == 0) {
 				logger.info("创建器件索引失败,原因:器件数据文件不存在!");
 				return 0L;
@@ -326,7 +323,7 @@ public class IndexServiceImpl implements IndexService {
 		Long size = 0L;
 		try {
 			// 从本地路径读取批次数据
-			File[] files = new File(luceneProperties.getGoodsDir()).listFiles();
+			File[] files = new File(SearchUtils.getDataPath(SearchConstants.GOODS_TABLE_NAME)).listFiles();
 			if (files == null || files.length == 0) {
 				logger.info("创建批次索引失败,原因:批次数据文件不存在!");
 				return 0L;
@@ -452,11 +449,12 @@ public class IndexServiceImpl implements IndexService {
 		PrintWriter printWriter = null;
 		int count = 0;
 		try {
-			File file = new File(luceneProperties.getComponentsDir());
+			String componentDataPath = SearchUtils.getDataPath(SearchConstants.COMPONENT_TABLE_NAME);
+			File file = new File(componentDataPath);
 			if (!file.exists()) {
 				file.mkdirs();
 			}
-			printWriter = new PrintWriter(luceneProperties.getComponentsDir() + "/" + fileIndex + ".txt");
+			printWriter = new PrintWriter(componentDataPath + "/" + fileIndex + ".txt");
 			while (totalElements > size) {
 				// 一个文件存放100000条数据,一旦超过,写入新的文件
 				if (count == SINGLE_FILE_MAX_SIZE) {
@@ -464,7 +462,7 @@ public class IndexServiceImpl implements IndexService {
 					printWriter.flush();
 					printWriter.close();
 					fileIndex++;
-					printWriter = new PrintWriter(luceneProperties.getComponentsDir() + "/" + fileIndex + ".txt");
+					printWriter = new PrintWriter(componentDataPath + "/" + fileIndex + ".txt");
 				}
 				List<ComponentSimpleInfo> content = pageResult.getContent();
 				for (ComponentSimpleInfo element : content) {

+ 15 - 1
search-console/src/main/java/com/uas/search/console/util/SearchUtils.java

@@ -317,7 +317,7 @@ public class SearchUtils {
 			return SearchConstants.COMPONENT_TABLE_NAME;
 		} else if (clazz == GoodsSimpleInfo.class) {
 			return SearchConstants.GOODS_TABLE_NAME;
-		}else if (clazz == OrderSimpleInfo.class) {
+		} else if (clazz == OrderSimpleInfo.class) {
 			return SearchConstants.ORDER_TABLE_NAME;
 		} else if (clazz == OrderInvoiceSimpleInfo.class) {
 			return SearchConstants.ORDER_INVOICE_TABLE_NAME;
@@ -343,4 +343,18 @@ public class SearchUtils {
 		}
 		return luceneProperties.getIndexesDir() + "/" + tableName;
 	}
+
+	/**
+	 * 获取指定表的数据路径
+	 * 
+	 * @param tableName
+	 *            指定表
+	 * @return 数据路径
+	 */
+	public static String getDataPath(String tableName) {
+		if (tableName == null) {
+			return null;
+		}
+		return luceneProperties.getDataDir() + "/" + tableName;
+	}
 }