From 741e7fb4fee533af9f82bac41a04fc09613dd0d0 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 6 Jan 2023 14:32:24 +0800 Subject: [PATCH] :bug: IORuntimeException: Path [lucene/index/xxx] is not directory! --- .../com/rymcu/forest/lucene/util/PortfolioIndexUtil.java | 6 +++++- .../java/com/rymcu/forest/lucene/util/UserIndexUtil.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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));