Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix lucene indexation when copying files accross workspaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Oct 17, 2015
1 parent 2115463 commit bb86928
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php
Expand Up @@ -429,62 +429,74 @@ public function updateNodeIndex($oldNode, $newNode = null, $copy = false, $recur
{
require_once("Zend/Search/Lucene.php");
if (isSet($this->currentIndex)) {
$index = $this->currentIndex;
$oldIndex = $newIndex = $this->currentIndex;
} else {
if($oldNode == null){
$index = $this->loadIndex($newNode->getRepositoryId(), true, $newNode->getUser());
$newIndex = $oldIndex = $this->loadIndex($newNode->getRepositoryId(), true, $newNode->getUser());
}else if($newNode == null){
$oldIndex = $newIndex = $this->loadIndex($oldNode->getRepositoryId(), true, $oldNode->getUser());
}else{
$index = $this->loadIndex($oldNode->getRepositoryId(), true, $oldNode->getUser());
$newId = $newNode->getRepositoryId();
$oldId = $oldNode->getRepositoryId();
if($newId == $oldId){
$newIndex = $oldIndex = $this->loadIndex($newNode->getRepositoryId(), true, $newNode->getUser());
}else{
$newIndex = $this->loadIndex($newNode->getRepositoryId(), true, $newNode->getUser());
$oldIndex = $this->loadIndex($oldNode->getRepositoryId(), true, $oldNode->getUser());
}
}
}
$this->setDefaultAnalyzer();
if ($oldNode != null && $copy == false) {
$oldDocId = $this->getIndexedDocumentId($index, $oldNode);
$oldDocId = $this->getIndexedDocumentId($oldIndex, $oldNode);
if ($oldDocId != null) {
$index->delete($oldDocId);
$oldIndex->delete($oldDocId);
if ($newNode == null) { // DELETION
$childrenHits = $this->getIndexedChildrenDocuments($index, $oldNode);
$childrenHits = $this->getIndexedChildrenDocuments($oldIndex, $oldNode);
foreach ($childrenHits as $hit) {
$index->delete($hit->id);
$oldIndex->delete($hit->id);
}
}
}
}

if ($newNode != null) {
// Make sure it does not already exists anyway
$newDocId = $this->getIndexedDocumentId($index, $newNode);
$newDocId = $this->getIndexedDocumentId($newIndex, $newNode);
if ($newDocId != null) {
$index->delete($newDocId);
$childrenHits = $this->getIndexedChildrenDocuments($index, $newNode);
$newIndex->delete($newDocId);
$childrenHits = $this->getIndexedChildrenDocuments($newIndex, $newNode);
foreach ($childrenHits as $hit) {
$index->delete($hit->id);
$newIndex->delete($hit->id);
}
}
$this->createIndexedDocument($newNode, $index);
$this->createIndexedDocument($newNode, $newIndex);
if ( $recursive && $oldNode == null && is_dir($newNode->getUrl())) {
$this->recursiveIndexation($newNode->getUrl());
}
}

if ($oldNode != null && $newNode != null && is_dir($newNode->getUrl())) { // Copy / Move / Rename
if ($oldNode != null && $newNode != null && is_dir($newNode->getUrl()) && ($newIndex == $oldIndex)) { // Copy / Move / Rename
// Get old node children docs, and update them manually, no need to scan real directory
$childrenHits = $this->getIndexedChildrenDocuments($index, $oldNode);
$childrenHits = $this->getIndexedChildrenDocuments($oldIndex, $oldNode);
foreach ($childrenHits as $hit) {
$oldChildURL = $index->getDocument($hit->id)->node_url;
$oldChildURL = $oldIndex->getDocument($hit->id)->node_url;
if ($copy == false) {
$index->delete($hit->id);
$oldIndex->delete($hit->id);
}
$newChildURL = str_replace(SystemTextEncoding::toUTF8($oldNode->getUrl()),
SystemTextEncoding::toUTF8($newNode->getUrl()),
$oldChildURL);
$newChildURL = SystemTextEncoding::fromUTF8($newChildURL);
$this->createIndexedDocument(new AJXP_Node($newChildURL), $index);
$this->createIndexedDocument(new AJXP_Node($newChildURL), $oldIndex);
}
}

if (!isSet($this->currentIndex)) {
$index->commit();
$oldIndex->commit();
if($newIndex != $oldIndex){
$newIndex->commit();
}
}
}

Expand Down

0 comments on commit bb86928

Please sign in to comment.