🐛 空指针异常修复
This commit is contained in:
parent
82cdf1d4d1
commit
8e6707f7fd
@ -9,6 +9,7 @@ import org.apache.lucene.index.IndexWriterConfig;
|
|||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,29 +20,29 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
*/
|
*/
|
||||||
public class UserBeanIndex extends BaseIndex<UserLucene> {
|
public class UserBeanIndex extends BaseIndex<UserLucene> {
|
||||||
|
|
||||||
public UserBeanIndex(
|
public UserBeanIndex(
|
||||||
String parentIndexPath,
|
String parentIndexPath,
|
||||||
int subIndex,
|
int subIndex,
|
||||||
CountDownLatch countDownLatch1,
|
CountDownLatch countDownLatch1,
|
||||||
CountDownLatch countDownLatch2,
|
CountDownLatch countDownLatch2,
|
||||||
List<UserLucene> list) {
|
List<UserLucene> list) {
|
||||||
super(parentIndexPath, subIndex, countDownLatch1, countDownLatch2, list);
|
super(parentIndexPath, subIndex, countDownLatch1, countDownLatch2, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexDoc(IndexWriter writer, UserLucene user) throws Exception {
|
public void indexDoc(IndexWriter writer, UserLucene user) throws Exception {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
Field id = new Field("id", user.getIdUser() + "", TextField.TYPE_STORED);
|
Field id = new Field("id", user.getIdUser() + "", TextField.TYPE_STORED);
|
||||||
Field title = new Field("nickname", user.getNickname(), TextField.TYPE_STORED);
|
Field title = new Field("nickname", user.getNickname(), TextField.TYPE_STORED);
|
||||||
Field summary = new Field("signature", user.getSignature(), TextField.TYPE_STORED);
|
Field summary = new Field("signature", Objects.nonNull(user.getSignature()) ? user.getSignature() : "", TextField.TYPE_STORED);
|
||||||
// 添加到Document中
|
// 添加到Document中
|
||||||
doc.add(id);
|
doc.add(id);
|
||||||
doc.add(title);
|
doc.add(title);
|
||||||
doc.add(summary);
|
doc.add(summary);
|
||||||
if (writer.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE) {
|
if (writer.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE) {
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
} else {
|
} else {
|
||||||
writer.updateDocument(new Term("id", user.getIdUser() + ""), doc);
|
writer.updateDocument(new Term("id", user.getIdUser() + ""), doc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user