|
|
@@ -0,0 +1,497 @@
|
|
|
+package com.giantan.data.dk.repository;
|
|
|
+
|
|
|
+import com.giantan.data.dk.constant.DkConstants;
|
|
|
+import com.giantan.data.dk.dto.GTool;
|
|
|
+import com.giantan.data.index.HybridIndexer;
|
|
|
+import com.giantan.data.index.IHybridSearch;
|
|
|
+import com.giantan.data.index.IndexConfig;
|
|
|
+import com.giantan.data.index.dto.DocReq;
|
|
|
+import com.giantan.data.index.dto.DocResp;
|
|
|
+//import com.giantan.data.kvs.repository.GEntity;
|
|
|
+//import com.giantan.data.kvs.repository.GEntityConfig;
|
|
|
+import com.giantan.data.qa.service.IQaCollectionService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
|
+import org.springframework.stereotype.Repository;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.invoke.MethodHandles;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Repository
|
|
|
+public class DkIndexer extends HybridIndexer implements IDkIndexer {
|
|
|
+ private static final org.slf4j.Logger log
|
|
|
+ = org.slf4j.LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
|
|
+
|
|
|
+
|
|
|
+ String cellectionPrefix = "dks_";
|
|
|
+
|
|
|
+ String splitter = "\n";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IHybridSearch hybridSearch;
|
|
|
+
|
|
|
+
|
|
|
+ // ICollectionMapper collMapper;
|
|
|
+ IQaCollectionService collectionService;
|
|
|
+
|
|
|
+ public DkIndexer() {
|
|
|
+ //collMapper = new DefaultCollectionMapper();
|
|
|
+ defaultIndexPrefix = "dks";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(IQaCollectionService collectionService) {
|
|
|
+ // 根据 params的attributes
|
|
|
+ setCollectionService(collectionService);
|
|
|
+ }
|
|
|
+
|
|
|
+ public IQaCollectionService getCollectionService() {
|
|
|
+ return collectionService;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCollectionService(IQaCollectionService collectionService) {
|
|
|
+ this.collectionService = collectionService;
|
|
|
+ }
|
|
|
+
|
|
|
+// public ICollectionMapper getCollMapper() {
|
|
|
+// return collMapper;
|
|
|
+// }
|
|
|
+//
|
|
|
+// public void setCollMapper(ICollectionMapper collMapper) {
|
|
|
+// this.collMapper = collMapper;
|
|
|
+// }
|
|
|
+
|
|
|
+ private void buildMetadata(String collection, GTool entity, DocReq req) {
|
|
|
+ Map<String, Object> metadata = req.getMetadata();
|
|
|
+ if (metadata == null) {
|
|
|
+ metadata = new HashMap<>();
|
|
|
+ req.setMetadata(metadata);
|
|
|
+ }
|
|
|
+ metadata.put(DOC_ID, entity.getId().toString());
|
|
|
+ metadata.put(COLL_ID, collection);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String indexName(String coll) {
|
|
|
+ return defaultIndexPrefix + "_" + coll;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String indexName(String prefix, String coll) {
|
|
|
+ return prefix + coll;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMappedIndexName(String collId) {
|
|
|
+ String collName = collectionService.getCollectionName(Integer.parseInt(collId));
|
|
|
+ String mapped = indexName(collName);
|
|
|
+ Map<String, Object> attibutes = collectionService.getAttibutes(collId);
|
|
|
+ String configIndexName = getConfigIndexName(collId, attibutes);
|
|
|
+ if (configIndexName != null) {
|
|
|
+ mapped = configIndexName;
|
|
|
+ }
|
|
|
+ return mapped;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isOne2One(String collId) {
|
|
|
+ boolean isOne2One = true;
|
|
|
+ Map<String, Object> attibutes = collectionService.getAttibutes(collId);
|
|
|
+
|
|
|
+ Boolean configOne2One = getConfigOne2One(attibutes);
|
|
|
+ if (configOne2One != null) {
|
|
|
+ isOne2One = configOne2One;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isOne2One;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getChunkMode(String coll) {
|
|
|
+ String chunkMode = defaultChunkMode;
|
|
|
+
|
|
|
+ Map<String, Object> attibutes = collectionService.getAttibutes(coll);
|
|
|
+
|
|
|
+ String configChunkMode = getConfigChunkMode(attibutes);
|
|
|
+ if (configChunkMode != null) {
|
|
|
+ chunkMode = configChunkMode;
|
|
|
+ }
|
|
|
+ return chunkMode;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getChunkTemplates(String coll) {
|
|
|
+ List<String> rets = null;
|
|
|
+ Map<String, Object> attibutes = collectionService.getAttibutes(coll);
|
|
|
+
|
|
|
+ List<String> configChunkTemplates = getConfigChunkTemplates(attibutes);
|
|
|
+ if (configChunkTemplates != null) {
|
|
|
+ rets = configChunkTemplates;
|
|
|
+ }
|
|
|
+ return rets;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<DocReq> toDocReq(String coll, GTool entity) {
|
|
|
+ String chunkMode = getChunkMode(coll);
|
|
|
+ List<DocReq> rets = null;
|
|
|
+// if (chunkMode.equals(IndexConfig.CHUNK_MODE_MULTIPLE)) {
|
|
|
+// rets = toDocReq2(coll, entity);
|
|
|
+// } else if (chunkMode.equals(IndexConfig.CHUNK_MODE_CUSTOM)) {
|
|
|
+// rets = toDocReq3(coll, entity);
|
|
|
+// } else {
|
|
|
+// rets = toDocReq1(coll, entity);
|
|
|
+// }
|
|
|
+
|
|
|
+ rets = toDocReq1(coll, entity);
|
|
|
+
|
|
|
+ return rets;
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO
|
|
|
+// private List<DocReq> toDocReq1(String coll, GTool entity) {
|
|
|
+// List<DocReq> lst = new ArrayList<DocReq>();
|
|
|
+// DocReq dr1 = new DocReq();
|
|
|
+// dr1.setId(entity.getGid());
|
|
|
+//
|
|
|
+// dr1.setTags(entity.getTags());
|
|
|
+// buildMetadata(coll, entity, dr1);
|
|
|
+//
|
|
|
+// StringBuilder sb = new StringBuilder();
|
|
|
+// sb.append(entity.getName());
|
|
|
+// if (entity.getDescription() != null) {
|
|
|
+// sb.append(entity.getDescription()).append(entity.getDescription());
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<String> altlabels = entity.getAltlabels();
|
|
|
+// if (altlabels != null && !altlabels.isEmpty()) {
|
|
|
+// for (int i = 0; i < altlabels.size(); i++) {
|
|
|
+// sb.append(splitter).append(altlabels.get(i));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// dr1.setText(sb.toString());
|
|
|
+// lst.add(dr1);
|
|
|
+// return lst;
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ private String buildBaseChunk(GTool entity) {
|
|
|
+ // 基础描述
|
|
|
+// String descChunk = String.format(
|
|
|
+// "[TOOL] %s\nType: %s\nPath: %s\nTags: %s\nDescription: %s",
|
|
|
+// tool.getName(), tool.getType(), tool.getPath(),
|
|
|
+// String.join(", ", tool.getTags()), tool.getDescription()
|
|
|
+// );
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ ret.append("[TOOL] ").append(entity.getName()).append(splitter);
|
|
|
+ if (entity.getPath() != null) {
|
|
|
+ ret.append("Path: ").append(entity.getPath()).append(splitter);
|
|
|
+ }
|
|
|
+ if (entity.getTags() != null) {
|
|
|
+ ret.append("Tags: ").append(String.join(", ", entity.getTags())).append(splitter);
|
|
|
+ }
|
|
|
+ if (entity.getDescription()!= null){
|
|
|
+ ret.append("Description: ").append(entity.getDescription()).append(splitter);
|
|
|
+ }
|
|
|
+ return ret.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildSchemaChunk(GTool entity) {
|
|
|
+ // String schemaChunk = String.format(
|
|
|
+ // "[SCHEMA] %s\nInput: %s\nOutput: %s",
|
|
|
+ // tool.getName(),
|
|
|
+ // tool.getInputSchema(),
|
|
|
+ // tool.getOutputSchema()
|
|
|
+ // );
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ ret.append("[SCHEMA] ").append(entity.getName()).append(splitter);
|
|
|
+ if (entity.getInputSchema() != null) {
|
|
|
+ ret.append("Input: ").append(entity.getInputSchema()).append(splitter);
|
|
|
+ }
|
|
|
+ if (entity.getOutputSchema() != null) {
|
|
|
+ ret.append("Output: ").append(entity.getOutputSchema()).append(splitter);
|
|
|
+ }
|
|
|
+ return ret.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildExampleChunk(GTool entity,Map<String,Object> ex) {
|
|
|
+ //chunks.add(new ToolChunk(tool.getId(), "usage",
|
|
|
+ // "[USAGE] " + tool.getName() + "\nExample: " + ex.toString()));
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ ret.append("[USAGE] ").append(entity.getName()).append(splitter);
|
|
|
+ ret.append("Example: ").append(ex.toString()).append(splitter);
|
|
|
+
|
|
|
+ return ret.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildDecisionKnowledgeChunk(GTool entity, String decision){
|
|
|
+ //chunks.add(new ToolChunk(tool.getId(), "knowledge",
|
|
|
+ //"[KNOWLEDGE] " + tool.getName() + "\nKnowledge: " + tool.getDecisionKnowledge().toString()));
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ ret.append("[KNOWLEDGE] ").append(entity.getName()).append(splitter);
|
|
|
+ ret.append("Knowledge: ").append(decision).append(splitter);
|
|
|
+
|
|
|
+ return ret.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<DocReq> toDocReq1(String coll, GTool entity) {
|
|
|
+ List<DocReq> lst = new ArrayList<DocReq>();
|
|
|
+ //**基础描述 chunk**
|
|
|
+ DocReq dr1 = new DocReq();
|
|
|
+ dr1.setId(entity.getGid() + "-0");
|
|
|
+ dr1.setText(buildBaseChunk(entity));
|
|
|
+ dr1.setTags(entity.getTags());
|
|
|
+ buildMetadata(coll, entity, dr1);
|
|
|
+
|
|
|
+ lst.add(dr1);
|
|
|
+
|
|
|
+ if (entity.getInputSchema() != null || entity.getOutputSchema() != null) {
|
|
|
+ String schemaChunk = buildSchemaChunk(entity);
|
|
|
+ DocReq dr2 = new DocReq();
|
|
|
+ dr2.setId(entity.getGid() + "-1");
|
|
|
+ dr2.setText(schemaChunk);
|
|
|
+ dr2.setTags(entity.getTags());
|
|
|
+ buildMetadata(coll, entity, dr2);
|
|
|
+ lst.add(dr2);
|
|
|
+ }
|
|
|
+
|
|
|
+ int idx = 2;
|
|
|
+ if (entity.getUsageExamples() != null) {
|
|
|
+ for (Map<String,Object> ex : entity.getUsageExamples()) {
|
|
|
+ String exampleChunk = buildExampleChunk(entity,ex);
|
|
|
+ DocReq dr2 = new DocReq();
|
|
|
+ dr2.setId(entity.getGid() + "-"+idx);
|
|
|
+ dr2.setText(exampleChunk);
|
|
|
+ dr2.setTags(entity.getTags());
|
|
|
+ buildMetadata(coll, entity, dr2);
|
|
|
+ lst.add(dr2);
|
|
|
+ idx++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (DkConstants.TOOL_TYPE_DECISION.equals(entity.getType()) && entity.getDecisionKnowledge() != null) {
|
|
|
+ Map<String, Object> knowledge = entity.getDecisionKnowledge();
|
|
|
+ Object decisionText = knowledge.get(DkConstants.DECISION_TEXT);
|
|
|
+ if (decisionText != null) {
|
|
|
+ DocReq dr2 = new DocReq();
|
|
|
+ dr2.setId(entity.getGid() + "-"+idx);
|
|
|
+ dr2.setText(buildDecisionKnowledgeChunk(entity,decisionText.toString()));
|
|
|
+ dr2.setTags(entity.getTags());
|
|
|
+ buildMetadata(coll, entity, dr2);
|
|
|
+ lst.add(dr2);
|
|
|
+ idx++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lst;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ExpressionParser parser = new SpelExpressionParser();
|
|
|
+ // Expression expression = parser.parseExpression(expressionString);
|
|
|
+ //
|
|
|
+ // // 上下文
|
|
|
+ // StandardEvaluationContext context = new StandardEvaluationContext();
|
|
|
+ // context.setVariables(variables);
|
|
|
+ //
|
|
|
+ // // 计算结果
|
|
|
+ // String chunk = expression.getValue(context, String.class);
|
|
|
+
|
|
|
+// private StandardEvaluationContext buildContext(GEntity entity) {
|
|
|
+// Map<String, Object> variables = new HashMap<>();
|
|
|
+// variables.put(GEntityConfig.NAME, entity.getName());
|
|
|
+// 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();
|
|
|
+// context.setVariables(variables);
|
|
|
+// return context;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ private List<DocReq> toDocReq3(String coll, GTool entity) {
|
|
|
+ List<String> templates = getChunkTemplates(coll);
|
|
|
+ if (templates == null || templates.isEmpty()) {
|
|
|
+ return toDocReq1(coll, entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DocReq> lst = new ArrayList<DocReq>();
|
|
|
+ //TODO
|
|
|
+
|
|
|
+// StandardEvaluationContext context = buildContext(entity);
|
|
|
+// ExpressionParser parser = new SpelExpressionParser();
|
|
|
+//
|
|
|
+// if (templates.size() == 1) {
|
|
|
+// Expression expression = parser.parseExpression(templates.get(0));
|
|
|
+// String chunk = expression.getValue(context, String.class);
|
|
|
+// DocReq dr1 = new DocReq();
|
|
|
+// dr1.setId(entity.getGid());
|
|
|
+// dr1.setTags(entity.getTags());
|
|
|
+// dr1.setText(chunk);
|
|
|
+// buildMetadata(coll, entity, dr1);
|
|
|
+// lst.add(dr1);
|
|
|
+// } else {
|
|
|
+// for (int i = 0; i < templates.size(); i++) {
|
|
|
+// Expression expression = parser.parseExpression(templates.get(i));
|
|
|
+// String chunk = expression.getValue(context, String.class);
|
|
|
+// DocReq dr1 = new DocReq();
|
|
|
+// dr1.setId(entity.getGid() + "-" + i);
|
|
|
+// dr1.setTags(entity.getTags());
|
|
|
+// dr1.setText(chunk);
|
|
|
+// buildMetadata(coll, entity, dr1);
|
|
|
+// lst.add(dr1);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ return lst;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onAdd(String collection, GTool entity) throws IOException, InterruptedException {
|
|
|
+ log.info("{}{} onAdd: {}", cellectionPrefix, collection, entity.getName());
|
|
|
+ List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
|
+ return rs == null ? 0 : rs.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onAdd(String collection, List<GTool> entities) throws IOException, InterruptedException {
|
|
|
+ log.info("{}{} onAdd: size = {}", cellectionPrefix, collection, entities.size());
|
|
|
+ List<DocReq> ls = new ArrayList<>();
|
|
|
+ for (GTool e : entities) {
|
|
|
+ List<DocReq> docReqs = toDocReq(collection, e);
|
|
|
+ ls.addAll(docReqs);
|
|
|
+ }
|
|
|
+ List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), ls);
|
|
|
+ return rs == null ? 0 : rs.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onDelete(String collection, GTool entity) {
|
|
|
+ log.info("{}{} onDelete: {}", cellectionPrefix, collection, entity.getName());
|
|
|
+ String gid = entity.getGid();
|
|
|
+ int i = 0;
|
|
|
+ try {
|
|
|
+ i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), gid);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onDelete(String collection, List<GTool> entities) {
|
|
|
+ log.info("{}{} onDelete: size = {}", cellectionPrefix, collection, entities.size());
|
|
|
+ int count = 0;
|
|
|
+ try {
|
|
|
+ for (GTool e : entities) {
|
|
|
+ String gid = e.getGid();
|
|
|
+ count = count + hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), gid);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onUpdate(String collection, GTool entity) throws IOException, InterruptedException {
|
|
|
+ log.info("{}{} onUpdate: {}", cellectionPrefix, collection, entity.getName());
|
|
|
+
|
|
|
+ int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
|
+ List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
|
+ return rs == null ? 0 : rs.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onUpdateField(String collection, GTool entity, String field) {
|
|
|
+ log.info("{}{} onUpdateField: ret = {}, field = {}", cellectionPrefix, collection, entity.getGid(), field);
|
|
|
+ int count = 0;
|
|
|
+ try {
|
|
|
+ int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), entity.getGid());
|
|
|
+ List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, entity));
|
|
|
+ count += rs == null ? 0 : rs.size();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onUpdateField(String collection, List<GTool> entities, String field) {
|
|
|
+ log.info("{}{} onUpdateField: size = {}, field = {}", cellectionPrefix, collection, entities.size(), field);
|
|
|
+ int count = 0;
|
|
|
+ try {
|
|
|
+ for (GTool e : entities) {
|
|
|
+ int i = hybridSearch.deleteDocumentsByIdFilter(getMappedIndexName(collection), e.getGid());
|
|
|
+ List<DocResp> rs = hybridSearch.add(getMappedIndexName(collection), toDocReq(collection, e));
|
|
|
+ count += rs == null ? 0 : rs.size();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int createCollection(String collection) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onDeleteAll(String collection) {
|
|
|
+ boolean b = false;
|
|
|
+ try {
|
|
|
+ if (isOne2One(collection)) {
|
|
|
+ b = hybridSearch.clearCollection(getMappedIndexName(collection));
|
|
|
+ } else {
|
|
|
+ //TODO 特殊处理
|
|
|
+ // "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) {
|
|
|
+ log.error("Collection {} onDeleteAll: {}", collection, e.getMessage());
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteCollection(String collection) {
|
|
|
+ boolean b = false;
|
|
|
+ try {
|
|
|
+ if (isOne2One(collection)) {
|
|
|
+ b = hybridSearch.dropCollection(getMappedIndexName(collection));
|
|
|
+ } else {
|
|
|
+ //TODO 特殊处理
|
|
|
+ // "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) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|