|
@@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
*
|
|
*
|
|
|
* <p><b>案件上下文从哪来</b>:{@link CaseContextHolder#get()}(只读 ThreadLocal)。
|
|
* <p><b>案件上下文从哪来</b>:{@link CaseContextHolder#get()}(只读 ThreadLocal)。
|
|
|
* 清洗任务跑在虚拟线程 / 线程池上,调用方必须先用
|
|
* 清洗任务跑在虚拟线程 / 线程池上,调用方必须先用
|
|
|
- * {@link CaseContextHolder#runWith(Long, Runnable)} 显式绑定案件 ID;
|
|
|
|
|
|
|
+ * {@link CaseContextHolder#runWith(Long, Long, Runnable)} 显式绑定案件 ID;
|
|
|
* 取不到时本类会抛异常明确失败,而不是静默写到错误的索引里。
|
|
* 取不到时本类会抛异常明确失败,而不是静默写到错误的索引里。
|
|
|
*/
|
|
*/
|
|
|
public class LuceneManager {
|
|
public class LuceneManager {
|
|
@@ -47,10 +47,14 @@ public class LuceneManager {
|
|
|
|
|
|
|
|
private static final int BATCH_SIZE = 1000;
|
|
private static final int BATCH_SIZE = 1000;
|
|
|
|
|
|
|
|
- /** caseId → 索引资源 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * caseId → 索引资源
|
|
|
|
|
+ */
|
|
|
private static final Map<Long, Holder> HOLDERS = new ConcurrentHashMap<>();
|
|
private static final Map<Long, Holder> HOLDERS = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
- /** caseId → 攒批缓冲 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * caseId → 攒批缓冲
|
|
|
|
|
+ */
|
|
|
private static final Map<Long, List<SearchDTO>> BUFFERS = new ConcurrentHashMap<>();
|
|
private static final Map<Long, List<SearchDTO>> BUFFERS = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
private LuceneManager() {
|
|
private LuceneManager() {
|
|
@@ -162,7 +166,9 @@ public class LuceneManager {
|
|
|
logger.info("段合并完成, caseId={}", caseId);
|
|
logger.info("段合并完成, caseId={}", caseId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 关闭指定案件的索引资源(退出案件时调用) */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 关闭指定案件的索引资源(退出案件时调用)
|
|
|
|
|
+ */
|
|
|
public static void close(Long caseId) {
|
|
public static void close(Long caseId) {
|
|
|
if (caseId == null) {
|
|
if (caseId == null) {
|
|
|
return;
|
|
return;
|
|
@@ -175,7 +181,9 @@ public class LuceneManager {
|
|
|
closeHolder(holder, caseId);
|
|
closeHolder(holder, caseId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 关闭全部案件的索引资源(应用停止时调用) */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 关闭全部案件的索引资源(应用停止时调用)
|
|
|
|
|
+ */
|
|
|
public static void closeAll() {
|
|
public static void closeAll() {
|
|
|
BUFFERS.clear();
|
|
BUFFERS.clear();
|
|
|
HOLDERS.forEach((caseId, holder) -> closeHolder(holder, caseId));
|
|
HOLDERS.forEach((caseId, holder) -> closeHolder(holder, caseId));
|