Explorar el Código

器件联想词返回uuid;建索引时添加uuid

sunyj hace 9 años
padre
commit
1fa8b633db

+ 1 - 1
search-api/src/main/java/com/uas/search/service/SearchService.java

@@ -103,7 +103,7 @@ public interface SearchService {
 	 * 根据输入的原厂型号获取联想词
 	 * 
 	 * @param componentCode
-	 * @return 包括id、code
+	 * @return 包括id、uuid、code
 	 */
 	public List<Map<String, Object>> getSimilarComponents(String componentCode);
 

+ 16 - 2
search-console/src/main/java/com/uas/search/console/model/ComponentSimpleInfo.java

@@ -35,6 +35,12 @@ public class ComponentSimpleInfo implements Serializable {
 	@Column(name = "cmp_id")
 	private Long id;
 
+	/**
+	 * 器件的uuid
+	 */
+	@Column(name = "cmp_uuid", unique = true)
+	private String uuid;
+
 	/**
 	 * 原厂型号
 	 */
@@ -69,6 +75,14 @@ public class ComponentSimpleInfo implements Serializable {
 		this.id = id;
 	}
 
+	public String getUuid() {
+		return uuid;
+	}
+
+	public void setUuid(String uuid) {
+		this.uuid = uuid;
+	}
+
 	public String getCode() {
 		return code;
 	}
@@ -103,8 +117,8 @@ public class ComponentSimpleInfo implements Serializable {
 
 	@Override
 	public String toString() {
-		return "ComponentSimpleInfo [id=" + id + ", code=" + code + ", kindid=" + kindid + ", brandid=" + brandid
-				+ ", properties=" + properties + "]";
+		return "ComponentSimpleInfo [id=" + id + ", uuid=" + uuid + ", code=" + code + ", kindid=" + kindid
+				+ ", brandid=" + brandid + ", properties=" + properties + "]";
 	}
 
 }

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

@@ -306,13 +306,14 @@ public class IndexServiceImpl implements IndexService {
 	 * @return
 	 */
 	private Document toDocument(ComponentSimpleInfo component) {
-		if (component == null || component.getId() == null || StringUtils.isEmpty(component.getCode())
+		if (component == null || component.getId() == null || StringUtils.isEmpty(component.getUuid()) || StringUtils.isEmpty(component.getCode())
 				|| component.getKindid() == null || component.getBrandid() == null) {
 			return null;
 		}
 		Document document = new Document();
 		// 不用LongField
 		document.add(new StringField(SearchConstants.COMPONENT_ID_FIELD, String.valueOf(component.getId()), Store.YES));
+		document.add(new StringField(SearchConstants.COMPONENT_UUID_FIELD, component.getUuid(), Store.YES));
 		// 转小写,以避免分词,又不会因大小写影响搜索
 		String code = component.getCode().toLowerCase();
 		document.add(new StringField(SearchConstants.COMPONENT_CODE_FIELD, code, Store.YES));

+ 6 - 1
search-console/src/main/java/com/uas/search/console/service/impl/SearchServiceImpl.java

@@ -551,9 +551,14 @@ public class SearchServiceImpl implements SearchService {
 			TopDocs hits = searcher.search(booleanQuery, SIMILAR_NUM);
 			ScoreDoc[] scoreDocs = hits.scoreDocs;
 			for (ScoreDoc scoreDoc : scoreDocs) {
-				Document document = searcher.doc(scoreDoc.doc);
+				Set<String> fieldsToLoad = new HashSet<>();
+				fieldsToLoad.add(SearchConstants.COMPONENT_ID_FIELD);
+				fieldsToLoad.add(SearchConstants.COMPONENT_UUID_FIELD);
+				fieldsToLoad.add(SearchConstants.COMPONENT_CODE_FIELD);
+				Document document = searcher.doc(scoreDoc.doc, fieldsToLoad);
 				Map<String, Object> map = new HashMap<>();
 				map.put("id", Long.parseLong(document.get(SearchConstants.COMPONENT_ID_FIELD)));
+				map.put("uuid", document.get(SearchConstants.COMPONENT_UUID_FIELD));
 				map.put("code", document.get(SearchConstants.COMPONENT_CODE_FIELD));
 				result.add(map);
 			}

+ 6 - 5
search-console/src/main/java/com/uas/search/console/util/MergeComponentData.java

@@ -33,8 +33,8 @@ public class MergeComponentData {
 	 * 将从本地文件读取的一行字符串数据解析为器件对象
 	 * 
 	 * @param data
-	 *            格式为"CMP_ID" "CMP_BRID" "CMP_CODE" "CMP_KIID",如1 149
-	 *            "10120-5212PC" 295
+	 *            格式为"CMP_ID" "CMP_BRID" "CMP_CODE" "CMP_KIID" "CMP_UUID",如1 149
+	 *            "10120-5212PC" 295 "2502600600000001"
 	 * @return
 	 */
 	private static ComponentSimpleInfo parseComponent(String data) {
@@ -44,6 +44,7 @@ public class MergeComponentData {
 		component.setBrandid(Long.parseLong(strs[1]));
 		component.setCode(strs[2].substring(1, strs[2].length() - 1));
 		component.setKindid(Long.parseLong(strs[3]));
+		component.setUuid(strs[4].substring(1, strs[4].length() - 1));
 		return component;
 	}
 
@@ -95,8 +96,8 @@ public class MergeComponentData {
 					printWriter.flush();
 					printWriter.close();
 					fileIndex++;
-					printWriter = new PrintWriter(DATA_DIR + "\\components\\ComponentWithProperty_" + fileIndex
-							+ ".txt");
+					printWriter = new PrintWriter(
+							DATA_DIR + "\\components\\ComponentWithProperty_" + fileIndex + ".txt");
 				}
 
 				ComponentSimpleInfo component = parseComponent(componentLine);
@@ -119,7 +120,7 @@ public class MergeComponentData {
 			}
 			printWriter.flush();
 		} catch (FileNotFoundException e) {
-			System.out.println("File not found!");
+			e.printStackTrace();
 		} catch (IOException e) {
 			e.printStackTrace();
 		} finally {