2011-01-29 2 views
0

실제로 인덱스를 만들고 최적화하는 방법은 매번 레코드 조각을 만들고 최적화하여 한 번에 모두 변환하지 않는 것입니다. 지금 내가 직면하고있는 문제는 내가 색인에 생성 된 중복 된 문서/레코드를 얻는다는 것입니다. 색인에서 중복을 제거하기위한 함수 나 코드가 있는지 알아야합니다. 사전에 감사합니다. 젠드 lucene 인덱스에서 중복 된 문서를 제거

답변

0

고유 식별자 인 용어가 있어야합니다. 그런 다음 색인에 문서를 추가하기 전에 삭제하십시오.

중복은 동일한 고유 ID를 가진 여러 문서가있는 인스턴스입니다. 따라서 고유 ID 필드의 모든 용어를 열거하고 두 가지 결과가있는 용어를 검색하면됩니다. 내가 아는 한이를 수행 할 내장 된 방법은 없습니다.

2

업데이트하기 전에 레코드를 제거해야합니다. Lucene이 작동하는 방식입니다. 기존 레코드가 있으면 업데이트 할 수 없습니다.

이 당신이 지금 당신은 기본적으로 삽입 :)되는 업데이트를 할 수있는 기록

$index = Zend_Search_Lucene::open('data/index');//'data/index' is the file that lucene generated 
$query = new Zend_Search_Lucene_Search_Query_Term(new 
Zend_Search_Lucene_Index_Term($listing_id, 'listing_id'));// 'listing_id' is a field i added when creating index for the first time. $listing_id is the id value of the row i want to delete 
$hits = $index->find($query); 
foreach ($hits as $hit) { 
    $index->delete($hit->id);// $hit->id is not listing_id, it's lucene unique index of the row that has listing_id = $listing_id 
} 

을 삭제하는 방법, 즉 방식 루씬 작업입니다.

0

새 데이터를 추가하기 전에 커밋 $index->commit()을 잊지 마십시오. 그것이 내 복제 데이터가 $index->find($query)에 반환되는 이유입니다.

$index = Zend_Search_Lucene::open('/lucene/index'); 
$query = new Zend_Search_Lucene_Search_Query_Term (new Zend_Search_Lucene_Index_Term($id, 'key')); 

$hits = $index->find($query); 
foreach ($hits as $hit) { 
     $index->delete($hit->id); // $hit->id is not key , it's lucene unique index of the row that has key = $id 
} 
$index->commit(); // apply changes (delete) before index new data 

doc = new Zend_Search_Lucene_Document(); 
$doc->addField(Zend_Search_Lucene_Field::keyword('key', $id)); 
$doc->addField(Zend_Search_Lucene_Field::Text('user', $user, 'utf-8'));