2012-05-11 7 views
1

이 문제는 이전에 아무런 문제가 없었고 일반적인 수정이 적용되지 않는 것을 제외하면 일반적인 문제입니다. 아마 어리석은 일이지만, 나는 그것을 찾을 수 없다.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()); 
+0

lucene 사용 3.4.0 btw – Rhand

+0

그리고 doc 카운트를 찾기 위해 어떤 API 호출이 사용됩니까? –

+0

수 있습니다. 'maxDoc'를 호출하면 삭제 된 문서를 고려하지 않는 것으로 알려져 있습니다. 물론 Lucene API 호출에 대해 말하고 있습니다. 그것 이상의 아무것도. –

답변

1

나는 몇 가지 테스트 코드를 실행하지 않고 확실하지 않다, 그러나 이것은 나에게 잘못 보인다 : 다음

Term key = new Term(YammerMessageFields.THREAD_ID, 
    newdoc.getFieldable(YammerMessageFields.THREAD_ID).stringValue()); 

당신 :

Term key = new Term(YammerMessageFields.THREAD_ID, 
    newdoc.getFieldable(YammerMessageFields.THREAD_ID).toString()); 

당신이 확인이 안 있습니까 그 키를 사용하여 일치하는 기존. 서를 갱신하려고 시도하십시오. 키가 잘못되면 문서 업데이트가 자동으로 실패합니다. 그 Term에있는 toString()이 실제로 당신에게 Object 레퍼런스를 줄 것이라고 생각합니다. 이는 업데이트가 절대로 작동하지 않는다는 것을 의미합니다.

로깅 또는 디버깅 이외의 작업 (즉, 로직이있는 모든 작업)은 일반적으로 실수입니다.

+0

이상으로 추가하면 .stringValue()가 문제를 해결했습니다. 이상하게도 고맙습니다, 다른 버전에서 작동했습니다 ... – Rhand

+0

아니, 그게 이상하지 않습니다. 프로그래머는 종종 toString() 메소드의 구현을 변경한다. 그렇기 때문에 특정 가치를 반환하는 것에 의존해서는 안됩니다. – Jon

+0

btw 업데이트가 실패하지 않았 으면 문서가 실제로 추가되고 실패한 것만 삭제됩니다. – Rhand

관련 문제