|
@@ -1,7 +1,9 @@
|
|
|
package com.giantan.data.mds.service.impl;
|
|
package com.giantan.data.mds.service.impl;
|
|
|
|
|
|
|
|
import com.giantan.data.kvs.kvstore.GBaseKeyValue;
|
|
import com.giantan.data.kvs.kvstore.GBaseKeyValue;
|
|
|
|
|
+import com.giantan.data.mds.repository.MdDynamicChunkRepository;
|
|
|
import com.giantan.data.mds.repository.MdDynamicRepository;
|
|
import com.giantan.data.mds.repository.MdDynamicRepository;
|
|
|
|
|
+import com.giantan.data.mds.repository.MdIndexer;
|
|
|
import com.giantan.data.mds.service.IMdDocsService;
|
|
import com.giantan.data.mds.service.IMdDocsService;
|
|
|
import com.giantan.gfs.service.impl.S3GkbService;
|
|
import com.giantan.gfs.service.impl.S3GkbService;
|
|
|
import com.giantan.gfs.storer.util.FileUtil;
|
|
import com.giantan.gfs.storer.util.FileUtil;
|
|
@@ -14,7 +16,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -52,6 +56,15 @@ public class MdDocsService implements IMdDocsService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
MdDynamicRepository mdDynamicRepository;
|
|
MdDynamicRepository mdDynamicRepository;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ MdDynamicChunkRepository mdDynamicChunkRepository;
|
|
|
|
|
+
|
|
|
|
|
+ //@Autowired
|
|
|
|
|
+ //IHybridSearch hybridSearch;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ MdIndexer mdIndexer;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
MdCache mdCache;
|
|
MdCache mdCache;
|
|
|
|
|
|
|
@@ -71,15 +84,15 @@ public class MdDocsService implements IMdDocsService {
|
|
|
return Integer.toString(id);
|
|
return Integer.toString(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected String normalizePath(String path){
|
|
|
|
|
- if (path == null || path.length() == 0){
|
|
|
|
|
|
|
+ protected String normalizePath(String path) {
|
|
|
|
|
+ if (path == null || path.length() == 0) {
|
|
|
return "/";
|
|
return "/";
|
|
|
}
|
|
}
|
|
|
- path = path.replaceAll("\\\\","/");
|
|
|
|
|
- if (path.startsWith("/")){
|
|
|
|
|
|
|
+ path = path.replaceAll("\\\\", "/");
|
|
|
|
|
+ if (path.startsWith("/")) {
|
|
|
return path;
|
|
return path;
|
|
|
- }else {
|
|
|
|
|
- return "/"+path;
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return "/" + path;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -98,12 +111,12 @@ public class MdDocsService implements IMdDocsService {
|
|
|
} else {
|
|
} else {
|
|
|
objectPath = p;
|
|
objectPath = p;
|
|
|
int i1 = p.lastIndexOf("/");
|
|
int i1 = p.lastIndexOf("/");
|
|
|
- p = p.substring(0,i1+1);
|
|
|
|
|
|
|
+ p = p.substring(0, i1 + 1);
|
|
|
}
|
|
}
|
|
|
int collId = mdCollectionsService.getCollectionOrNew(coll);
|
|
int collId = mdCollectionsService.getCollectionOrNew(coll);
|
|
|
|
|
|
|
|
- params.put("path",p);
|
|
|
|
|
- params.put("name",objectPath);
|
|
|
|
|
|
|
+ params.put("path", p);
|
|
|
|
|
+ params.put("name", objectPath);
|
|
|
//TaskStatus status = new TaskStatus(coll, taskId, "成功", "处理完成", System.currentTimeMillis(), System.currentTimeMillis());
|
|
//TaskStatus status = new TaskStatus(coll, taskId, "成功", "处理完成", System.currentTimeMillis(), System.currentTimeMillis());
|
|
|
//taskStatusManager.markSuccess(taskId, status);
|
|
//taskStatusManager.markSuccess(taskId, status);
|
|
|
ret.put("taskId", taskId);
|
|
ret.put("taskId", taskId);
|
|
@@ -176,7 +189,7 @@ public class MdDocsService implements IMdDocsService {
|
|
|
public int deleteByMdid(String coll, String gid) throws Throwable {
|
|
public int deleteByMdid(String coll, String gid) throws Throwable {
|
|
|
GBaseKeyValue kv = findByMdid(coll, gid);
|
|
GBaseKeyValue kv = findByMdid(coll, gid);
|
|
|
if (kv == null) {
|
|
if (kv == null) {
|
|
|
- log.error("该 {} 不存在", gid);
|
|
|
|
|
|
|
+ log.error("该 id: {} 不存在", gid);
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
return doDelete(coll, kv);
|
|
return doDelete(coll, kv);
|
|
@@ -198,7 +211,7 @@ public class MdDocsService implements IMdDocsService {
|
|
|
public int deleteByPathPrefix(String coll, String prefix) throws Throwable {
|
|
public int deleteByPathPrefix(String coll, String prefix) throws Throwable {
|
|
|
String collId = getStrOfCollId(coll);
|
|
String collId = getStrOfCollId(coll);
|
|
|
List<GBaseKeyValue> kvs = mdDynamicRepository.findByPath(collId, prefix);
|
|
List<GBaseKeyValue> kvs = mdDynamicRepository.findByPath(collId, prefix);
|
|
|
- if (kvs == null || kvs.size()<=0){
|
|
|
|
|
|
|
+ if (kvs == null || kvs.size() <= 0) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
int count = mdDynamicRepository.deleteByPrefix(collId, prefix);
|
|
int count = mdDynamicRepository.deleteByPrefix(collId, prefix);
|
|
@@ -229,7 +242,6 @@ public class MdDocsService implements IMdDocsService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
private String getKvObjectName(String coll, Map<String, Object> req) throws Throwable {
|
|
private String getKvObjectName(String coll, Map<String, Object> req) throws Throwable {
|
|
|
String collId = getStrOfCollId(coll);
|
|
String collId = getStrOfCollId(coll);
|
|
|
Object o = req.get(FIELD_NAME);
|
|
Object o = req.get(FIELD_NAME);
|
|
@@ -281,7 +293,7 @@ public class MdDocsService implements IMdDocsService {
|
|
|
String collId = getStrOfCollId(coll);
|
|
String collId = getStrOfCollId(coll);
|
|
|
|
|
|
|
|
String mdid = getKvObjectId(collId, req);
|
|
String mdid = getKvObjectId(collId, req);
|
|
|
- MdSearcher searcher = getSearcher2(coll,collId, mdid);
|
|
|
|
|
|
|
+ MdSearcher searcher = getSearcher2(coll, collId, mdid);
|
|
|
|
|
|
|
|
Object o1 = req.get(QUERY_TEXT);
|
|
Object o1 = req.get(QUERY_TEXT);
|
|
|
Map<String, Object> map = searcher.searchAndHeadings((String) o1);
|
|
Map<String, Object> map = searcher.searchAndHeadings((String) o1);
|
|
@@ -291,7 +303,7 @@ public class MdDocsService implements IMdDocsService {
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private MdSearcher getSearcher2(String coll, String collId,String id) throws Throwable {
|
|
|
|
|
|
|
+ private MdSearcher getSearcher2(String coll, String collId, String id) throws Throwable {
|
|
|
String key = coll + ":" + id;
|
|
String key = coll + ":" + id;
|
|
|
MdSearcher searcher = mdCache.get(key);
|
|
MdSearcher searcher = mdCache.get(key);
|
|
|
if (searcher == null) {
|
|
if (searcher == null) {
|
|
@@ -332,9 +344,9 @@ public class MdDocsService implements IMdDocsService {
|
|
|
id = (String) o;
|
|
id = (String) o;
|
|
|
} else {
|
|
} else {
|
|
|
o = req.get(FIELD_MDID2);
|
|
o = req.get(FIELD_MDID2);
|
|
|
- if (o!=null){
|
|
|
|
|
|
|
+ if (o != null) {
|
|
|
id = (String) o;
|
|
id = (String) o;
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
o = req.get(FIELD_GID);
|
|
o = req.get(FIELD_GID);
|
|
|
String gid = null;
|
|
String gid = null;
|
|
|
if (o != null) {
|
|
if (o != null) {
|
|
@@ -369,7 +381,6 @@ public class MdDocsService implements IMdDocsService {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
private String getMdFileContentById(String coll, String fn) throws Exception {
|
|
private String getMdFileContentById(String coll, String fn) throws Exception {
|
|
|
String repository = coll;
|
|
String repository = coll;
|
|
|
String fromObject = getObjectPath("", fn);
|
|
String fromObject = getObjectPath("", fn);
|
|
@@ -541,24 +552,25 @@ public class MdDocsService implements IMdDocsService {
|
|
|
String r = gkbStorer.renameFile(coll, oldName, newName);
|
|
String r = gkbStorer.renameFile(coll, oldName, newName);
|
|
|
GBaseKeyValue value = GBaseKeyValue.build();
|
|
GBaseKeyValue value = GBaseKeyValue.build();
|
|
|
int i1 = newName.lastIndexOf('/');
|
|
int i1 = newName.lastIndexOf('/');
|
|
|
- String path = newName.substring(0,i1+1);
|
|
|
|
|
- value.put("path",path);
|
|
|
|
|
|
|
+ String path = newName.substring(0, i1 + 1);
|
|
|
|
|
+ value.put("path", path);
|
|
|
value.setName(newName);
|
|
value.setName(newName);
|
|
|
value.setId(intId);
|
|
value.setId(intId);
|
|
|
|
|
|
|
|
GBaseKeyValue updated = mdDynamicRepository.update(collId, value);
|
|
GBaseKeyValue updated = mdDynamicRepository.update(collId, value);
|
|
|
|
|
|
|
|
return updated;
|
|
return updated;
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
return Map.of("error", "No supported fields to update");
|
|
return Map.of("error", "No supported fields to update");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public String getIndexName(String coll) {
|
|
|
|
|
- return mdDynamicRepository.indexName(coll);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public String getIndexName(String coll) {
|
|
|
|
|
+// //return mdDynamicRepository.indexName(coll);
|
|
|
|
|
+// return mdCollectionsService.getIndexName(coll);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> locateByHeading(String coll, Map<String, Object> req) throws Throwable {
|
|
public Map<String, Object> locateByHeading(String coll, Map<String, Object> req) throws Throwable {
|
|
@@ -567,13 +579,74 @@ public class MdDocsService implements IMdDocsService {
|
|
|
//MdSearcher searcher = getSearcher(coll, name);
|
|
//MdSearcher searcher = getSearcher(coll, name);
|
|
|
String collId = getStrOfCollId(coll);
|
|
String collId = getStrOfCollId(coll);
|
|
|
String mdid = getKvObjectId(collId, req);
|
|
String mdid = getKvObjectId(collId, req);
|
|
|
- MdSearcher searcher = getSearcher2(coll,collId, mdid);
|
|
|
|
|
|
|
+ MdSearcher searcher = getSearcher2(coll, collId, mdid);
|
|
|
|
|
|
|
|
Map<String, Object> ret = searcher.searchByHeadings(headings);
|
|
Map<String, Object> ret = searcher.searchByHeadings(headings);
|
|
|
ret.put(QUERY_HEADINGS, headings);
|
|
ret.put(QUERY_HEADINGS, headings);
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ //删除 md,同时删 chunk 和 index。
|
|
|
|
|
+ public int deleteCascadeByMdid(String coll, String gid) throws Throwable {
|
|
|
|
|
+ String collId = getStrOfCollId(coll);
|
|
|
|
|
+ GBaseKeyValue kv = findByMdid(coll, gid);
|
|
|
|
|
+ if (kv == null) {
|
|
|
|
|
+ log.error("该 id: {} 不存在", gid);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer mdId = kv.getIntId();
|
|
|
|
|
+// List<Map<String, Object>> rets = mdDynamicChunkRepository.getKeywordsByMdId(collId, mdId);
|
|
|
|
|
+// List<String> objects = new ArrayList<>();
|
|
|
|
|
+// if (rets != null) {
|
|
|
|
|
+// for (Map<String, Object> ret : rets) {
|
|
|
|
|
+// Object o = ret.get("id");
|
|
|
|
|
+// objects.add(o.toString());
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// if (objects.size() >0){
|
|
|
|
|
+// int deleted = hybridSearch.delete(coll, objects);
|
|
|
|
|
+// log.info("删除索引文件: {}", gid);
|
|
|
|
|
+// long deleted2 = mdDynamicChunkRepository.deleteByMdId(collId,mdId);
|
|
|
|
|
+// log.info("删除chunk文件: {}", gid);
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ List<String> uids = mdDynamicChunkRepository.findUidsByMdId(collId, mdId);
|
|
|
|
|
+ if (uids != null && !uids.isEmpty()) {
|
|
|
|
|
+ //hybridSearch.delete(coll, uids);
|
|
|
|
|
+ mdIndexer.delete(coll,uids);
|
|
|
|
|
+ log.info("删除索引文件,mdid: {}", gid);
|
|
|
|
|
+ long r = mdDynamicChunkRepository.deleteByMdId(collId, mdId);
|
|
|
|
|
+ log.info("删除chunk文件,mdid: {}", gid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return doDelete(coll, kv);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int deleteIndexesByMdid(String coll, String gid) throws Throwable {
|
|
|
|
|
+ String collId = getStrOfCollId(coll);
|
|
|
|
|
+ GBaseKeyValue kv = findByMdid(coll, gid);
|
|
|
|
|
+ if (kv == null) {
|
|
|
|
|
+ log.error("该 id: {} 不存在", gid);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer mdId = kv.getIntId();
|
|
|
|
|
+ List<String> uids = mdDynamicChunkRepository.findUidsByMdId(collId, mdId);
|
|
|
|
|
+ if (uids != null && !uids.isEmpty()) {
|
|
|
|
|
+ //hybridSearch.delete(coll, uids);
|
|
|
|
|
+ mdIndexer.delete(coll,uids);
|
|
|
|
|
+ log.info("删除索引文件,mdid: {}", gid);
|
|
|
|
|
+ //long r = mdDynamicChunkRepository.deleteByMdId(collId, mdId);
|
|
|
|
|
+ //log.info("删除chunk文件: {}", gid);
|
|
|
|
|
+ }
|
|
|
|
|
+ return uids.size();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //mdDynamicChunkRepository
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
///////////////////////
|
|
///////////////////////
|
|
|
// renameByPath / deleteByPath
|
|
// renameByPath / deleteByPath
|
|
|
|
|
|