|
|
@@ -7,6 +7,7 @@ import com.uas.search.annotation.NotEmpty;
|
|
|
import com.uas.search.constant.SearchConstants;
|
|
|
import com.uas.search.constant.model.PageInfo;
|
|
|
import com.uas.search.constant.model.PageParams;
|
|
|
+import com.uas.search.constant.model.SPage;
|
|
|
import com.uas.search.dao.*;
|
|
|
import com.uas.search.exception.SearchException;
|
|
|
import com.uas.search.jms.JmsListener;
|
|
|
@@ -21,6 +22,8 @@ import com.uas.search.util.SearchUtils;
|
|
|
import org.apache.lucene.document.Document;
|
|
|
import org.apache.lucene.index.IndexWriter;
|
|
|
import org.apache.lucene.index.Term;
|
|
|
+import org.apache.lucene.search.BooleanClause;
|
|
|
+import org.apache.lucene.search.BooleanQuery;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -857,4 +860,42 @@ public class IndexServiceImpl implements IndexService {
|
|
|
return maintainIndexes(parsedQueueMessage);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Object> updateIndexByNewWords(List<String> newWords) {
|
|
|
+ List<Object> updatedObjects = new ArrayList<>();
|
|
|
+ updatedObjects.add(updateIndexByNewWords(newWords, SearchConstants.KIND_TABLE_NAME, SearchConstants.KIND_ID_FIELD, SearchConstants.KIND_NAMECN_FIELD));
|
|
|
+ updatedObjects.add(updateIndexByNewWords(newWords, SearchConstants.BRAND_TABLE_NAME, SearchConstants.BRAND_ID_FIELD, SearchConstants.BRAND_NAMECN_FIELD, SearchConstants.BRAND_NAMEEN_FIELD));
|
|
|
+ updatedObjects.add(updateIndexByNewWords(newWords, SearchConstants.COMPONENT_TABLE_NAME, SearchConstants.COMPONENT_ID_FIELD, SearchConstants.COMPONENT_KINDNAME_FIELD));
|
|
|
+ updatedObjects.add(updateIndexByNewWords(newWords, SearchConstants.COMPONENT_TABLE_NAME, SearchConstants.COMPONENT_ID_FIELD, SearchConstants.COMPONENT_BRANDNAMECN_FIELD, SearchConstants.COMPONENT_BRANDNAMEEN_FIELD));
|
|
|
+ return updatedObjects;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据(录入的词典)新词更新指定表的索引
|
|
|
+ *
|
|
|
+ * @param newWords 词典新词
|
|
|
+ * @param tableName 表名
|
|
|
+ * @param idField id 字段名称
|
|
|
+ * @param fields 新词可能牵涉到的字段名称
|
|
|
+ * @return 更新的对象
|
|
|
+ */
|
|
|
+ private List<Object> updateIndexByNewWords(List<String> newWords, String tableName, String idField, String... fields) {
|
|
|
+ List<Object> updatedObjects = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(newWords)) {
|
|
|
+ BooleanQuery booleanQuery = new BooleanQuery();
|
|
|
+ for (String newWord : newWords) {
|
|
|
+ for (String field : fields) {
|
|
|
+ booleanQuery.add(SearchUtils.getBooleanQuery(field, newWord, false, BooleanClause.Occur.MUST), BooleanClause.Occur.SHOULD);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info(booleanQuery.toString());
|
|
|
+ SPage<Document> documents = SearchUtils.getDocuments(tableName, booleanQuery, null,
|
|
|
+ SearchConstants.TOP_NUM);
|
|
|
+ for (Document document : documents.getContent()) {
|
|
|
+ updatedObjects.add(maintainIndexes(tableName, Long.parseLong(document.get(idField)), "update", null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return updatedObjects;
|
|
|
+ }
|
|
|
+
|
|
|
}
|