これはこれまでに何の問題もなく、通常の修正が機能しないという点を除いて、共通の問題です。それはおそらく愚かなものですが、私はそれを見つけることができません。Lucene updateDocumentはドキュメントを削除しません
yammer apiが私の目的には十分に速くないため、yammerサイトのインデックスを作成したいのですが、問題は、updateDocument機能を使用してインデックスを更新しようとすると古いものが削除されないということです。しかし、私は分析されていない格納されたユニークなキーを持っています。
Document newdoc = new Document();
newdoc.add(new Field(YammerMessageFields.URL, resultUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
newdoc.add(new Field(YammerMessageFields.THREAD_ID, threadID.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
newdoc.add(new Field(YammerMessageFields.AUTHOR, senderName, Field.Store.YES, Field.Index.ANALYZED));
newdoc.add(new Field(YammerMessageFields.CONTENTS, resultText, Field.Store.YES, Field.Index.ANALYZED));
Term key = new Term(YammerMessageFields.THREAD_ID, newdoc.getFieldable(YammerMessageFields.THREAD_ID).toString());
logger.debug("updating document with key: " + key);
try {
IndexWriter writer = getIndexWriter();
writer.updateDocument(key, newdoc);
writer.close();
} catch (IOException e) {
}
私は私のログに表示することである:ここで
は、関連するコードです
2012-05-11 12:02:29,816 DEBUG [http-8088-2] LuceneIndex - https://www.yammer.com/api/v1/messages/?newer_than=0
2012-05-11 12:02:38,594 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173285202>
2012-05-11 12:02:45,167 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173033239>
2012-05-11 12:02:51,686 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173014568>
2012-05-11 12:02:51,871 DEBUG [http-8088-2] LuceneIndex - new items:3
2012-05-11 12:03:27,393 DEBUG [http-8088-2] YammerResource - return all documents
2012-05-11 12:03:27,405 DEBUG [http-8088-2] YammerResource - nr docs:3
2012-05-11 12:03:27,405 DEBUG [http-8088-2] YammerResource - nr dels:0
...
next update
...
2012-05-11 12:03:35,802 DEBUG [http-8088-2] LuceneIndex - https://www.yammer.com/api/v1/messages/?newer_than=0
2012-05-11 12:03:43,933 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173322760>
2012-05-11 12:03:50,467 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173285202>
2012-05-11 12:03:56,982 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173056406>
2012-05-11 12:04:03,533 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173033239>
2012-05-11 12:04:10,097 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173030769>
2012-05-11 12:04:16,629 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173014568>
2012-05-11 12:04:23,169 DEBUG [http-8088-2] LuceneIndex - updating document with key: threadid:stored,indexed<threadid:173003570>
2012-05-11 12:04:23,341 DEBUG [http-8088-2] LuceneIndex - new items:7
2012-05-11 12:05:09,694 DEBUG [http-8088-1] YammerResource - return all documents
2012-05-11 12:05:09,696 DEBUG [http-8088-1] YammerResource - nr docs:10
2012-05-11 12:05:09,696 DEBUG [http-8088-1] YammerResource - nr dels:0
ので、キーが再発(と4つの新しいもの)が、これはある行われたとき私の店では7の代わりに10の文書(そして3つは削除された文書)。
編集:ここでアイテムを見つける方法はありますが、実際にはそれらを表示してルークで検査しました。
IndexReader r = IndexReader.open(searchIndex.getIndex());
List<Document> docList = new ArrayList<Document>();
List<Document> delList = new ArrayList<Document>();
int num = r.numDocs();
num += r.numDeletedDocs();
for (int i = 0; i < num && i < max; i++)
{
if (! r.isDeleted(i))
docList.add(r.document(i));
else
delList.add(r.document(i));
}
r.close();
logger.debug("nr docs:" + docList.size());
logger.debug("nr dels:" + delList.size());
luceneの使用3.4.0 btw – Rhand
そして、何番目のAPIコールがドキュメント数を見つけるために使われていますか? –
することができます。 'maxDoc'を呼び出すと、削除されたドキュメントを考慮しないことがわかります。私はもちろん、LuceneのAPI呼び出しについて話しています。それ以上のものはありません。 –