From 96739bf1cf6adbebfc3bdf3b3e6194c7fd8e7871 Mon Sep 17 00:00:00 2001 From: Suwen <577014284@qq.com> Date: Mon, 22 Feb 2021 15:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=20=E4=BF=AE=E5=A4=8DarticleLucene?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加luceneArticle增加更新接口 --- .../service/impl/LuceneServiceImpl.java | 27 +++++++++++++------ .../mapper/lucene/ArticleLuceneMapper.xml | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java index 20349dc..86c1370 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java @@ -83,7 +83,8 @@ public class LuceneServiceImpl implements LuceneService { @Override public void writeArticle(String id) throws Exception { - writeArticle(luceneMapper.getById(id), true); + // TODO 做新增或更新判断 + writeArticle(luceneMapper.getById(id), false); } @Override @@ -92,20 +93,30 @@ public class LuceneServiceImpl implements LuceneService { } @Override - public void deleteArticle(String id) {} + public void deleteArticle(String id) { + try { + deleteIndex(id); + } catch (IOException e) { + e.printStackTrace(); + } + } private void writeArticle(ArticleLucene article, boolean create) throws Exception { if (!create) { - int size = Objects.requireNonNull(new File(indexPath).listFiles()).length; - while (size-- >= 0) { - ArticleBeanIndex index = new ArticleBeanIndex(indexPath, size); - index.deleteDoc(article.getIdArticle()); - } + deleteIndex(article.getIdArticle()); } - ArticleBeanIndex index = new ArticleBeanIndex(indexPath, 0x0); + ArticleBeanIndex index = new ArticleBeanIndex(indexPath, 777); index.indexDoc(article); } + private void deleteIndex(String id) throws IOException { + int size = Objects.requireNonNull(new File(indexPath).listFiles()).length; + while (size-- >= 0) { + ArticleBeanIndex index = new ArticleBeanIndex(indexPath, size); + index.deleteDoc(id); + } + } + /** * 关键词搜索 * diff --git a/src/main/java/mapper/lucene/ArticleLuceneMapper.xml b/src/main/java/mapper/lucene/ArticleLuceneMapper.xml index 4df2a67..895c45a 100755 --- a/src/main/java/mapper/lucene/ArticleLuceneMapper.xml +++ b/src/main/java/mapper/lucene/ArticleLuceneMapper.xml @@ -62,7 +62,7 @@ - select art.id, art.article_title, content.article_content from forest_article art left join forest_article_content content on art.id = content.id_article