我从LuceneIndex
. 对于我的删除,我使用了术语查询。在我注意到文档没有被删除后,我尝试先搜索文档,但没有找到文档。
我像这样存储我的文档:
public boolean storeNote(Note note) throws Exception {
Document doc = new Document();
this.initalizeWriter(OpenMode.CREATE_OR_APPEND);
if (note != null && note.getUri() != null && note.getPatientUri() != null && !note.getUri().isEmpty()
&& !note.getPatientUri().isEmpty()) {
doc.add(new TextField(URINOTE, note.getUri(), Field.Store.YES));
doc.add(new TextField(URIPATIENT, note.getPatientUri(), Field.Store.YES));
if (note.getTitle() != null && !note.getTitle().isEmpty()) {
doc.add(new TextField(NOTETITLE, note.getTitle(), Field.Store.YES));
}
if (note.getText() != null && !note.getText().isEmpty()) {
doc.add(new TextField(NOTETEXT, note.getText(), Field.Store.YES));
}
}
try
{
this.writer.addDocument(doc);
}
catch(Exception e)
{
LOGGER.info("DocSave Failed \n" + e.getMessage());
return false;
}
finally
{
// Ensure that index is closed. Open indexFiles are locked!
this.closeWriter();
}
return true;
}
将文档存储到我的索引中后,是时候删除它了,我尝试这样:
public boolean deleteNote(Note note) throws IOException
{
if(note == null || note .getUri() == null || note.getUri().isEmpty() )
return false;
LOGGER.info("Deleting Notes with URI '" + note.getPatientUri());
TermQuery deleteTerm = new TermQuery(new Term(URINOTE, note.getUri()));
try
{
this.initalizeWriter(OpenMode.CREATE_OR_APPEND);
this.writer.deleteDocuments(deleteTerm);
this.writer.commit();
LOGGER.info("Deleting for '" + note.getUri() + "done");
}
catch(Exception e)
{
this.writer.rollback();
LOGGER.info("Rollback for '" + note.getPatientUri() + "done \n");
LOGGER.info("Check Consitenzy");
}
finally
{
this.closeWriter();
}
return true;
}
String queryString = URIPATIENT + ":\"" + request.getPatientUri() + "\"";
Query query = new QueryParser(Version.LUCENE_43, NOTETEXT, analyzer).parse(queryString);
我的问题是我的 deleteTerm 没有返回任何结果。我通过我的 deleteTerm 搜索进行了尝试。
知道我在那里错过了什么吗?