|
@@ -7,7 +7,7 @@ import com.giantan.data.kvs.repository.GEntity;
|
|
|
import com.giantan.data.kvs.repository.GEntityConfig;
|
|
import com.giantan.data.kvs.repository.GEntityConfig;
|
|
|
import com.giantan.data.kvs.repository.index.IIndexer;
|
|
import com.giantan.data.kvs.repository.index.IIndexer;
|
|
|
import com.giantan.data.qa.constant.QaConstants;
|
|
import com.giantan.data.qa.constant.QaConstants;
|
|
|
-import com.giantan.data.qa.service.ICollectionService;
|
|
|
|
|
|
|
+import com.giantan.data.qa.service.IQaCollectionService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.expression.Expression;
|
|
import org.springframework.expression.Expression;
|
|
|
import org.springframework.expression.ExpressionParser;
|
|
import org.springframework.expression.ExpressionParser;
|
|
@@ -33,6 +33,8 @@ public class QaIndexer implements IIndexer {
|
|
|
String defaultIndexPrefix = "qas";
|
|
String defaultIndexPrefix = "qas";
|
|
|
String defaultChunkMode = "single";
|
|
String defaultChunkMode = "single";
|
|
|
|
|
|
|
|
|
|
+ String cellectionPrefix = "qas_";
|
|
|
|
|
+
|
|
|
String splitter = "\n";
|
|
String splitter = "\n";
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -40,23 +42,23 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
|
|
|
|
|
// ICollectionMapper collMapper;
|
|
// ICollectionMapper collMapper;
|
|
|
- ICollectionService collectionService;
|
|
|
|
|
|
|
+ IQaCollectionService collectionService;
|
|
|
|
|
|
|
|
public QaIndexer() {
|
|
public QaIndexer() {
|
|
|
//collMapper = new DefaultCollectionMapper();
|
|
//collMapper = new DefaultCollectionMapper();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void init(ICollectionService collectionService) {
|
|
|
|
|
|
|
+ public void init(IQaCollectionService collectionService) {
|
|
|
// 根据 params的attributes
|
|
// 根据 params的attributes
|
|
|
setCollectionService(collectionService);
|
|
setCollectionService(collectionService);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ICollectionService getCollectionService() {
|
|
|
|
|
|
|
+ public IQaCollectionService getCollectionService() {
|
|
|
return collectionService;
|
|
return collectionService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setCollectionService(ICollectionService collectionService) {
|
|
|
|
|
|
|
+ public void setCollectionService(IQaCollectionService collectionService) {
|
|
|
this.collectionService = collectionService;
|
|
this.collectionService = collectionService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -243,11 +245,23 @@ public class QaIndexer implements IIndexer {
|
|
|
// String chunk = expression.getValue(context, String.class);
|
|
// String chunk = expression.getValue(context, String.class);
|
|
|
private StandardEvaluationContext buildContext(GEntity entity) {
|
|
private StandardEvaluationContext buildContext(GEntity entity) {
|
|
|
Map<String, Object> variables = new HashMap<>();
|
|
Map<String, Object> variables = new HashMap<>();
|
|
|
- variables.put(GEntityConfig.ATTRIBUTES, entity.getAttributes());
|
|
|
|
|
variables.put(GEntityConfig.NAME, entity.getName());
|
|
variables.put(GEntityConfig.NAME, entity.getName());
|
|
|
- variables.put(GEntityConfig.ALTLABELS, entity.getAltlabels());
|
|
|
|
|
- variables.put(GEntityConfig.DESCRIPTION, entity.getDescription());
|
|
|
|
|
|
|
+ if (entity.getAttributes() != null) {
|
|
|
|
|
+ variables.put(GEntityConfig.ATTRIBUTES, entity.getAttributes());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ variables.put(GEntityConfig.ATTRIBUTES, new HashMap<>());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ if (entity.getAltlabels() != null) {
|
|
|
|
|
+ variables.put(GEntityConfig.ALTLABELS, entity.getAltlabels());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ variables.put(GEntityConfig.ALTLABELS, new ArrayList<String>());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (entity.getDescription() != null) {
|
|
|
|
|
+ variables.put(GEntityConfig.DESCRIPTION, entity.getDescription());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ variables.put(GEntityConfig.DESCRIPTION, "");
|
|
|
|
|
+ }
|
|
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
|
|
context.setVariables(variables);
|
|
context.setVariables(variables);
|
|
|
return context;
|
|
return context;
|
|
@@ -273,7 +287,7 @@ public class QaIndexer implements IIndexer {
|
|
|
dr1.setText(chunk);
|
|
dr1.setText(chunk);
|
|
|
buildMetadata(coll, entity, dr1);
|
|
buildMetadata(coll, entity, dr1);
|
|
|
lst.add(dr1);
|
|
lst.add(dr1);
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
for (int i = 0; i < templates.size(); i++) {
|
|
for (int i = 0; i < templates.size(); i++) {
|
|
|
Expression expression = parser.parseExpression(templates.get(i));
|
|
Expression expression = parser.parseExpression(templates.get(i));
|
|
|
String chunk = expression.getValue(context, String.class);
|
|
String chunk = expression.getValue(context, String.class);
|
|
@@ -290,14 +304,14 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onAdd(String collection, GEntity entity) throws IOException, InterruptedException {
|
|
public int onAdd(String collection, GEntity entity) throws IOException, InterruptedException {
|
|
|
- log.info("{} onAdd: {}", collection, entity.getName());
|
|
|
|
|
|
|
+ log.info("{}{} onAdd: {}", cellectionPrefix, collection, entity.getName());
|
|
|
List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
|
return rs == null ? 0 : rs.size();
|
|
return rs == null ? 0 : rs.size();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onAdd(String collection, List<GEntity> entities) throws IOException, InterruptedException {
|
|
public int onAdd(String collection, List<GEntity> entities) throws IOException, InterruptedException {
|
|
|
- log.info("{} onAdd: size = {}", collection, entities.size());
|
|
|
|
|
|
|
+ log.info("{}{} onAdd: size = {}", cellectionPrefix, collection, entities.size());
|
|
|
List<DocReq> ls = new ArrayList<>();
|
|
List<DocReq> ls = new ArrayList<>();
|
|
|
for (GEntity e : entities) {
|
|
for (GEntity e : entities) {
|
|
|
List<DocReq> docReqs = toDocReq(collection, e);
|
|
List<DocReq> docReqs = toDocReq(collection, e);
|
|
@@ -309,7 +323,7 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onDelete(String collection, GEntity entity) {
|
|
public int onDelete(String collection, GEntity entity) {
|
|
|
- log.info("{} onDelete: {}", collection, entity.getName());
|
|
|
|
|
|
|
+ log.info("{}{} onDelete: {}", cellectionPrefix, collection, entity.getName());
|
|
|
String gid = entity.getGid();
|
|
String gid = entity.getGid();
|
|
|
int i = 0;
|
|
int i = 0;
|
|
|
try {
|
|
try {
|
|
@@ -322,7 +336,7 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onDelete(String collection, List<GEntity> entities) {
|
|
public int onDelete(String collection, List<GEntity> entities) {
|
|
|
- log.info("{} onDelete: size = {}", collection, entities.size());
|
|
|
|
|
|
|
+ log.info("{}{} onDelete: size = {}", cellectionPrefix, collection, entities.size());
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
try {
|
|
try {
|
|
|
for (GEntity e : entities) {
|
|
for (GEntity e : entities) {
|
|
@@ -337,7 +351,7 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onUpdate(String collection, GEntity entity) throws IOException, InterruptedException {
|
|
public int onUpdate(String collection, GEntity entity) throws IOException, InterruptedException {
|
|
|
- log.info("{} onUpdate: {}", collection, entity.getName());
|
|
|
|
|
|
|
+ log.info("{}{} onUpdate: {}", cellectionPrefix, collection, entity.getName());
|
|
|
|
|
|
|
|
int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
|
List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
@@ -346,7 +360,7 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onUpdateField(String collection, GEntity entity, String field) {
|
|
public int onUpdateField(String collection, GEntity entity, String field) {
|
|
|
- log.info("{} onUpdateField: ret = {}, field = {}", collection, entity.getGid(), field);
|
|
|
|
|
|
|
+ log.info("{}{} onUpdateField: ret = {}, field = {}", cellectionPrefix, collection, entity.getGid(), field);
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
try {
|
|
try {
|
|
|
int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
@@ -361,7 +375,7 @@ public class QaIndexer implements IIndexer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onUpdateField(String collection, List<GEntity> entities, String field) {
|
|
public int onUpdateField(String collection, List<GEntity> entities, String field) {
|
|
|
- log.info("{} onUpdateField: size = {}, field = {}", collection, entities.size(), field);
|
|
|
|
|
|
|
+ log.info("{}{} onUpdateField: size = {}, field = {}", cellectionPrefix, collection, entities.size(), field);
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
try {
|
|
try {
|
|
|
for (GEntity e : entities) {
|
|
for (GEntity e : entities) {
|
|
@@ -390,6 +404,9 @@ public class QaIndexer implements IIndexer {
|
|
|
} else {
|
|
} else {
|
|
|
//TODO 特殊处理
|
|
//TODO 特殊处理
|
|
|
// "filterExpression": "metadata[\"__cid\"] == \"qas_2\""
|
|
// "filterExpression": "metadata[\"__cid\"] == \"qas_2\""
|
|
|
|
|
+ Map<String, Object> filterMap = Map.of("filterExpression", "metadata[\"__cid\"] == \"" + collection + "\"");
|
|
|
|
|
+ int r = hybridSearch.deleteDocumentsByFilter(getMappedIndexName(collection), filterMap);
|
|
|
|
|
+ return r;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
@@ -406,6 +423,9 @@ public class QaIndexer implements IIndexer {
|
|
|
} else {
|
|
} else {
|
|
|
//TODO 特殊处理
|
|
//TODO 特殊处理
|
|
|
// "filterExpression": "metadata[\"__cid\"] == \"qas_2\""
|
|
// "filterExpression": "metadata[\"__cid\"] == \"qas_2\""
|
|
|
|
|
+ Map<String, Object> filterMap = Map.of("filterExpression", "metadata[\"__cid\"] == \"" + collection + "\"");
|
|
|
|
|
+ int r = hybridSearch.deleteDocumentsByFilter(getMappedIndexName(collection), filterMap);
|
|
|
|
|
+ return r;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
@@ -413,5 +433,11 @@ public class QaIndexer implements IIndexer {
|
|
|
return b ? 0 : 1;
|
|
return b ? 0 : 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int clearCollection(String collection) throws IOException, InterruptedException {
|
|
|
|
|
+ Map<String, Object> filterMap = Map.of("filterExpression", "metadata[\"__cid\"] == \"" + collection + "\"");
|
|
|
|
|
+ int r = hybridSearch.deleteDocumentsByFilter(getMappedIndexName(collection), filterMap);
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|