diff --git a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java index aa1fc01..b9b19a4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/ArticleIndexUtil.java @@ -1,6 +1,7 @@ package com.rymcu.forest.lucene.util; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import com.rymcu.forest.lucene.model.ArticleLucene; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -23,8 +24,7 @@ public class ArticleIndexUtil { /** * lucene索引保存目录 */ - private static final String PATH = - LucenePath.ARTICLE_INDEX_PATH; + private static final String PATH = System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.ARTICLE_INDEX_PATH; /** * 删除所有运行中保存的索引 diff --git a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java index eddc824..7e255e4 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java @@ -23,7 +23,7 @@ public class PortfolioIndexUtil { /** * lucene索引保存目录 */ - private static final String PATH = LucenePath.PORTFOLIO_PATH; + private static final String PATH = System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.PORTFOLIO_PATH; /** * 删除所有运行中保存的索引 @@ -81,6 +81,7 @@ public class PortfolioIndexUtil { try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); writer.deleteDocuments(new Term("id", String.valueOf(id))); + writer.forceMerge(1); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close(); diff --git a/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java b/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java index aed1f7a..d876119 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java @@ -25,7 +25,7 @@ public class UserIndexUtil { /** * lucene索引保存目录 */ - private static final String PATH = LucenePath.USER_PATH; + private static final String PATH = System.getProperty("user.dir") + StrUtil.SLASH + LucenePath.USER_PATH; /** * 系统运行时索引保存目录 @@ -89,6 +89,7 @@ public class UserIndexUtil { try { writer = IndexUtil.getIndexWriter(each.getAbsolutePath(), false); writer.deleteDocuments(new Term("id", id)); + writer.forceMerge(1); writer.forceMergeDeletes(); // 强制删除 writer.commit(); writer.close();