|
|
@@ -171,14 +171,14 @@ public class IndexServiceImpl implements IndexService {
|
|
|
try {
|
|
|
// 从本地路径读取器件数据
|
|
|
File[] files = new File(SearchConstants.COMPONENT_WITH_PROPERTY_DIR).listFiles();
|
|
|
- // if(files.length == 0){
|
|
|
- // System.out.println("创建器件索引失败,原因:器件数据文件不存在!");
|
|
|
- // return 0L;
|
|
|
- // }
|
|
|
+ if (files == null || files.length == 0) {
|
|
|
+ System.out.println("创建器件索引失败,原因:器件数据文件不存在!");
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
// 将要创建的索引总数目约为:文件数目*单个文件的行数
|
|
|
- long totalSize = files.length * MergeComponentData.SIMGLE_FILE_MAX_SIZE;
|
|
|
+ long totalSize = files.length * MergeComponentData.SINGLE_FILE_MAX_SIZE;
|
|
|
for (File file : files) {
|
|
|
- System.out.println("创建器件索引自文件: " + file.getName());
|
|
|
+ System.out.println("读取文件: " + file.getName());
|
|
|
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
|
|
String line = null;
|
|
|
while (!StringUtils.isEmpty(line = bufferedReader.readLine())) {
|
|
|
@@ -206,7 +206,7 @@ public class IndexServiceImpl implements IndexService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 创建器件索引
|
|
|
+ * 创建器件索引,从数据库取数据
|
|
|
*
|
|
|
* @return 写入的器件索引数
|
|
|
* @throws IOException
|
|
|
@@ -315,8 +315,10 @@ public class IndexServiceImpl implements IndexService {
|
|
|
// 属性值加入索引,索引中field的键:"pr_"前缀连接属性的id
|
|
|
Set<PropertyValue> propertyValues = component.getProperties();
|
|
|
for (PropertyValue propertyValue : propertyValues) {
|
|
|
- String fieldKey = SearchConstants.COMPONENT_PROPERTY_PREFIX + propertyValue.getPropertyid();
|
|
|
- document.add(new StringField(fieldKey, propertyValue.getValue(), Store.YES));
|
|
|
+ if (!StringUtils.isEmpty(propertyValue.getValue())) {
|
|
|
+ String fieldKey = SearchConstants.COMPONENT_PROPERTY_PREFIX + propertyValue.getPropertyid();
|
|
|
+ document.add(new StringField(fieldKey, propertyValue.getValue(), Store.YES));
|
|
|
+ }
|
|
|
}
|
|
|
return document;
|
|
|
}
|