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 fe02abe..eddc824 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/PortfolioIndexUtil.java @@ -53,7 +53,11 @@ public class PortfolioIndexUtil { System.out.println("创建单个索引"); IndexWriter writer; try { - writer = IndexUtil.getIndexWriter(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH, false); + boolean create = true; + if (FileUtil.exist(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH)) { + create = false; + } + writer = IndexUtil.getIndexWriter(LucenePath.PORTFOLIO_INCREMENT_INDEX_PATH, create); Document doc = new Document(); doc.add(new StringField("id", t.getIdPortfolio() + "", Field.Store.YES)); doc.add(new TextField("title", t.getPortfolioTitle(), Field.Store.YES)); 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 db7f9cf..aed1f7a 100644 --- a/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java +++ b/src/main/java/com/rymcu/forest/lucene/util/UserIndexUtil.java @@ -60,7 +60,11 @@ public class UserIndexUtil { System.out.println("创建单个索引"); IndexWriter writer; try { - writer = IndexUtil.getIndexWriter(INDEX_PATH, false); + boolean create = true; + if (FileUtil.exist(LucenePath.USER_INCREMENT_INDEX_PATH)) { + create = false; + } + writer = IndexUtil.getIndexWriter(INDEX_PATH, create); Document doc = new Document(); doc.add(new StringField("id", t.getIdUser() + "", Field.Store.YES)); doc.add(new TextField("nickname", t.getNickname(), Field.Store.YES));