From 8e6707f7fd92019df85a85003aa1d677725ac37f Mon Sep 17 00:00:00 2001 From: ronger Date: Thu, 29 Apr 2021 10:18:03 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/lucene/lucene/UserBeanIndex.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/rymcu/forest/lucene/lucene/UserBeanIndex.java b/src/main/java/com/rymcu/forest/lucene/lucene/UserBeanIndex.java index 3ec5f04..0470a8f 100644 --- a/src/main/java/com/rymcu/forest/lucene/lucene/UserBeanIndex.java +++ b/src/main/java/com/rymcu/forest/lucene/lucene/UserBeanIndex.java @@ -9,6 +9,7 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import java.util.List; +import java.util.Objects; import java.util.concurrent.CountDownLatch; /** @@ -19,29 +20,29 @@ import java.util.concurrent.CountDownLatch; */ public class UserBeanIndex extends BaseIndex { - public UserBeanIndex( - String parentIndexPath, - int subIndex, - CountDownLatch countDownLatch1, - CountDownLatch countDownLatch2, - List list) { - super(parentIndexPath, subIndex, countDownLatch1, countDownLatch2, list); - } - - @Override - public void indexDoc(IndexWriter writer, UserLucene user) throws Exception { - Document doc = new Document(); - Field id = new Field("id", user.getIdUser() + "", TextField.TYPE_STORED); - Field title = new Field("nickname", user.getNickname(), TextField.TYPE_STORED); - Field summary = new Field("signature", user.getSignature(), TextField.TYPE_STORED); - // 添加到Document中 - doc.add(id); - doc.add(title); - doc.add(summary); - if (writer.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE) { - writer.addDocument(doc); - } else { - writer.updateDocument(new Term("id", user.getIdUser() + ""), doc); + public UserBeanIndex( + String parentIndexPath, + int subIndex, + CountDownLatch countDownLatch1, + CountDownLatch countDownLatch2, + List list) { + super(parentIndexPath, subIndex, countDownLatch1, countDownLatch2, list); + } + + @Override + public void indexDoc(IndexWriter writer, UserLucene user) throws Exception { + Document doc = new Document(); + Field id = new Field("id", user.getIdUser() + "", TextField.TYPE_STORED); + Field title = new Field("nickname", user.getNickname(), TextField.TYPE_STORED); + Field summary = new Field("signature", Objects.nonNull(user.getSignature()) ? user.getSignature() : "", TextField.TYPE_STORED); + // 添加到Document中 + doc.add(id); + doc.add(title); + doc.add(summary); + if (writer.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE) { + writer.addDocument(doc); + } else { + writer.updateDocument(new Term("id", user.getIdUser() + ""), doc); + } } - } }