Quellcode durchsuchen

索引中写入rowid

sunyj vor 9 Jahren
Ursprung
Commit
1b145139e2

+ 9 - 1
search-console/src/main/java/com/uas/search/console/dao/BrandSimpleInfoDao.java

@@ -20,5 +20,13 @@ public interface BrandSimpleInfoDao
 	 * @param id
 	 * @return
 	 */
-	public BrandSimpleInfo findById(Long id);
+	// public BrandSimpleInfo findById(Long id);
+
+	/**
+	 * 根据rowid获取品牌
+	 * 
+	 * @param rowid
+	 * @return
+	 */
+	public BrandSimpleInfo findByRowid(String rowid);
 }

+ 9 - 1
search-console/src/main/java/com/uas/search/console/dao/ComponentSimpleInfoDao.java

@@ -24,7 +24,15 @@ public interface ComponentSimpleInfoDao
 	 * @param id
 	 * @return
 	 */
-	public ComponentSimpleInfo findById(Long id);
+	// public ComponentSimpleInfo findById(Long id);
+
+	/**
+	 * 根据rowid获取器件
+	 * 
+	 * @param rowid
+	 * @return
+	 */
+	public ComponentSimpleInfo findByRowid(@Param("rowid") String rowid);
 
 	/**
 	 * 根据类目kindid获取器件

+ 10 - 1
search-console/src/main/java/com/uas/search/console/dao/KindSimpleInfoDao.java

@@ -20,5 +20,14 @@ public interface KindSimpleInfoDao
 	 * @param id
 	 * @return
 	 */
-	public KindSimpleInfo findById(Long id);
+	// public KindSimpleInfo findById(Long id);
+
+	/**
+	 * 根据rowid获取类目
+	 * 
+	 * @param rowid
+	 * @return
+	 */
+	public KindSimpleInfo findByRowid(String rowid);
+
 }

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

@@ -97,15 +97,16 @@ public class IndexServiceImpl implements IndexService {
 			indexWriter = indexWriterManager.get();
 			Long startTime = new Date().getTime();
 
-			Long kindSize = createKindIndexs();
+			Long kindSize = createKindIndexes();
 			Long kindTime = new Date().getTime();
 			logger.info("创建类目索引: " + kindSize + "条,耗时 " + (kindTime - startTime) + " ms\n");
 
-			Long brandSize = createBrandIndexs();
+			Long brandSize = createBrandIndexes();
 			Long brandTime = new Date().getTime();
 			logger.info("创建品牌索引: " + brandSize + "条,耗时 " + (brandTime - kindTime) + " ms\n");
 
-			Long componentSize = createComponentIndexesWithFiles();
+//			Long componentSize = createComponentIndexesWithFiles();
+			Long componentSize = createComponentIndexes();
 			Long componentTime = new Date().getTime();
 			logger.info("创建器件索引: " + componentSize + "条,耗时 " + (componentTime - brandTime) + " ms\n");
 
@@ -129,7 +130,7 @@ public class IndexServiceImpl implements IndexService {
 	 * @return 写入的类目索引数
 	 * @throws IOException
 	 */
-	private Long createKindIndexs() throws IOException {
+	private Long createKindIndexes() throws IOException {
 		logger.info("正在创建类目索引...");
 		List<KindSimpleInfo> kinds = kindDao.findAll();
 
@@ -137,6 +138,7 @@ public class IndexServiceImpl implements IndexService {
 			return 0L;
 
 		for (KindSimpleInfo kind : kinds) {
+			logger.info(kind);
 			Document document = toDocument(kind);
 			if (document != null)
 				indexWriter.addDocument(document);
@@ -151,13 +153,14 @@ public class IndexServiceImpl implements IndexService {
 	 * @return 写入的品牌索引数
 	 * @throws IOException
 	 */
-	private Long createBrandIndexs() throws IOException {
+	private Long createBrandIndexes() throws IOException {
 		logger.info("正在创建品牌索引...");
 		List<BrandSimpleInfo> brands = brandDao.findAll();
 		if (CollectionUtils.isEmpty(brands))
 			return 0L;
 
 		for (BrandSimpleInfo brand : brands) {
+			logger.info(brand);
 			Document document = toDocument(brand);
 			if (document != null) {
 				indexWriter.addDocument(document);
@@ -167,7 +170,7 @@ public class IndexServiceImpl implements IndexService {
 		return (long) brands.size();
 	}
 
-	private Long createComponentIndexesWithFiles() {
+	public Long createComponentIndexesWithFiles() {
 		logger.info("正在创建器件索引...");
 		Long size = 0L;
 		try {
@@ -213,7 +216,7 @@ public class IndexServiceImpl implements IndexService {
 	 * @return 写入的器件索引数
 	 * @throws IOException
 	 */
-	public Long createComponentIndexs() throws IOException {
+	public Long createComponentIndexes() throws IOException {
 		logger.info("正在创建器件索引...");
 		Long size = 0L;
 		PageParams params = new PageParams();
@@ -230,6 +233,7 @@ public class IndexServiceImpl implements IndexService {
 		while (totalElements > size) {
 			List<ComponentSimpleInfo> components = pageResult.getContent();
 			for (ComponentSimpleInfo component : components) {
+				logger.info(component);
 				Document document = toDocument(component);
 				if (document != null) {
 					indexWriter.addDocument(document);
@@ -263,16 +267,15 @@ public class IndexServiceImpl implements IndexService {
 	 */
 	private Document toDocument(KindSimpleInfo kind) {
 		if (kind == null || kind.getId() == null || StringUtils.isEmpty(kind.getNameCn()) || kind.getIsLeaf() == null
-				|| kind.getLevel() == null) {
+				|| kind.getLevel() == null || StringUtils.isEmpty(kind.getRowid())) {
 			return null;
 		}
 		Document document = new Document();
-		// 不能用LongField,否则后续实时更新索引时,方法updateDocument(new Term("", ""),
-		// doc)无法根据id进行更新
 		document.add(new StringField(SearchConstants.KIND_ID_FIELD, String.valueOf(kind.getId()), Store.YES));
 		document.add(new TextField(SearchConstants.KIND_NAMECN_FIELD, kind.getNameCn(), Store.YES));
 		document.add(new StringField(SearchConstants.KIND_ISLEAF_FIELD, String.valueOf(kind.getIsLeaf()), Store.YES));
 		document.add(new StringField(SearchConstants.KIND_LEVEL_FIELD, String.valueOf(kind.getLevel()), Store.YES));
+		document.add(new StringField(SearchConstants.KIND_ROWID_FIELD, kind.getRowid(), Store.YES));
 		return document;
 	}
 
@@ -284,20 +287,18 @@ public class IndexServiceImpl implements IndexService {
 	 */
 	private Document toDocument(BrandSimpleInfo brand) {
 		if (brand == null || brand.getId() == null || StringUtils.isEmpty(brand.getNameCn())
-				|| StringUtils.isEmpty(brand.getUuid())) {
+				|| StringUtils.isEmpty(brand.getUuid()) || StringUtils.isEmpty(brand.getRowid())) {
 			return null;
 		}
 		Document document = new Document();
 		document.add(new StringField(SearchConstants.BRAND_ID_FIELD, String.valueOf(brand.getId()), Store.YES));
-		String nameCn = brand.getNameCn();
-		if (!StringUtils.isEmpty(nameCn)) {
-			document.add(new TextField(SearchConstants.BRAND_NAMECN_FIELD, nameCn, Store.YES));
-		}
+		document.add(new TextField(SearchConstants.BRAND_NAMECN_FIELD, brand.getNameCn(), Store.YES));
 		String nameEn = brand.getNameEn();
 		if (!StringUtils.isEmpty(nameEn)) {
 			document.add(new TextField(SearchConstants.BRAND_NAMEEN_FIELD, nameEn, Store.YES));
 		}
 		document.add(new StringField(SearchConstants.BRAND_UUID_FIELD, brand.getUuid(), Store.YES));
+		document.add(new StringField(SearchConstants.BRAND_ROWID_FIELD, brand.getRowid(), Store.YES));
 		return document;
 	}
 
@@ -310,7 +311,7 @@ public class IndexServiceImpl implements IndexService {
 	private Document toDocument(ComponentSimpleInfo component) {
 		if (component == null || component.getId() == null || StringUtils.isEmpty(component.getUuid())
 				|| StringUtils.isEmpty(component.getCode()) || component.getKindid() == null
-				|| component.getBrandid() == null) {
+				|| component.getBrandid() == null || StringUtils.isEmpty(component.getRowid())) {
 			return null;
 		}
 		Document document = new Document();
@@ -323,6 +324,7 @@ public class IndexServiceImpl implements IndexService {
 				Store.YES));
 		document.add(new StringField(SearchConstants.COMPONENT_BRANDID_FIELD, String.valueOf(component.getBrandid()),
 				Store.YES));
+		document.add(new StringField(SearchConstants.COMPONENT_ROWID_FIELD, component.getRowid(), Store.YES));
 
 		// 属性值加入索引,索引中field的键:"pr_"前缀连接属性的id
 		Set<PropertyValue> propertyValues = component.getProperties();
@@ -411,22 +413,20 @@ public class IndexServiceImpl implements IndexService {
 				KindSimpleInfo kind = (KindSimpleInfo) obj;
 				Document document = toDocument(kind);
 				if (document != null) {
-					indexWriter.updateDocument(new Term(SearchConstants.KIND_ID_FIELD, String.valueOf(kind.getId())),
-							document);
+					indexWriter.updateDocument(new Term(SearchConstants.KIND_ROWID_FIELD, kind.getRowid()), document);
 				}
 			} else if (obj instanceof BrandSimpleInfo) {
 				BrandSimpleInfo brand = (BrandSimpleInfo) obj;
 				Document document = toDocument((BrandSimpleInfo) obj);
 				if (document != null) {
-					indexWriter.updateDocument(new Term(SearchConstants.BRAND_ID_FIELD, String.valueOf(brand.getId())),
-							document);
+					indexWriter.updateDocument(new Term(SearchConstants.BRAND_ROWID_FIELD, brand.getRowid()), document);
 				}
 			} else if (obj instanceof ComponentSimpleInfo) {
 				ComponentSimpleInfo component = (ComponentSimpleInfo) obj;
 				Document document = toDocument(component);
 				if (document != null) {
-					indexWriter.updateDocument(
-							new Term(SearchConstants.COMPONENT_ID_FIELD, String.valueOf(component.getId())), document);
+					indexWriter.updateDocument(new Term(SearchConstants.COMPONENT_ROWID_FIELD, component.getRowid()),
+							document);
 				}
 			} else {
 				logger.error("message parsing failed!");
@@ -450,14 +450,14 @@ public class IndexServiceImpl implements IndexService {
 		try {
 			indexWriter = indexWriterManager.get();
 			if (obj instanceof KindSimpleInfo) {
-				indexWriter.deleteDocuments(
-						new Term(SearchConstants.KIND_ID_FIELD, ((KindSimpleInfo) obj).getId().toString()));
+				indexWriter
+						.deleteDocuments(new Term(SearchConstants.KIND_ROWID_FIELD, ((KindSimpleInfo) obj).getRowid()));
 			} else if (obj instanceof BrandSimpleInfo) {
 				indexWriter.deleteDocuments(
-						new Term(SearchConstants.BRAND_ID_FIELD, ((BrandSimpleInfo) obj).getId().toString()));
+						new Term(SearchConstants.BRAND_ROWID_FIELD, ((BrandSimpleInfo) obj).getRowid()));
 			} else if (obj instanceof ComponentSimpleInfo) {
 				indexWriter.deleteDocuments(
-						new Term(SearchConstants.COMPONENT_ID_FIELD, ((ComponentSimpleInfo) obj).getId().toString()));
+						new Term(SearchConstants.COMPONENT_ROWID_FIELD, ((ComponentSimpleInfo) obj).getRowid()));
 			} else {
 				logger.error("message parsing failed!");
 			}

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

@@ -48,6 +48,11 @@ public class SearchConstants {
 	 */
 	public static final String COMPONENT_TABLE_NAME = "product$component";
 
+	/**
+	 * 属性值表明
+	 */
+	public static final String PROPERTYVALUE_TABLE_NAME = "product$propertyvalue";
+
 	/**
 	 * 索引文件存储路径
 	 */
@@ -65,12 +70,14 @@ public class SearchConstants {
 	public static final String KIND_NAMECN_FIELD = "ki_name_cn";
 	public static final String KIND_LEVEL_FIELD = "ki_level";
 	public static final String KIND_ISLEAF_FIELD = "ki_isleaf";
+	public static final String KIND_ROWID_FIELD = "ki_rowid";
 
 	public static final String BRAND_ID_FIELD = "br_id";
 	public static final String BRAND_NAMECN_FIELD = "br_name_cn";
 	public static final String BRAND_NAMEEN_FIELD = "br_name_en";
 	public static final String BRAND_UUID_FIELD = "br_uuid";
 	public static final String BRAND_WEIGHT_FIELD = "br_weight";
+	public static final String BRAND_ROWID_FIELD = "br_rowid";
 
 	public static final String COMPONENT_ID_FIELD = "cmp_id";
 	public static final String COMPONENT_UUID_FIELD = "cmp_uuid";
@@ -81,6 +88,7 @@ public class SearchConstants {
 	public static final String COMPONENT_BRANDID_FIELD = "cmp_brand_id";
 	public static final String COMPONENT_BRANDUUID_FIELD = "cmp_brand_uuid";
 	public static final String COMPONENT_BRANDNAME_FIELD = "cmp_brand_name_cn";
+	public static final String COMPONENT_ROWID_FIELD = "cmp_rowid";
 	/**
 	 * 创建器件属性的索引时,在属性id的前面添加该前缀作为Field的键
 	 */