Пример #1
0
 function testCamelCaseNotEnabled()
 {
     $index = new Search_Elastic_Index($this->connection, 'test_index');
     $index->destroy();
     $typeFactory = $index->getTypeFactory();
     $index->addDocument(['object_type' => $typeFactory->identifier('wiki page'), 'object_id' => $typeFactory->identifier('CamelCase Words'), 'title' => $typeFactory->plaintext('CamelCase Words')]);
     $query = new Search_Query();
     $query->filterContent('Camel AND Word', 'title');
     $this->assertEquals(0, count($query->search($index)));
 }
Пример #2
0
 /**
  * @param int $loggit 0=no logging, 1=log to Search_Indexer.log, 2=log to Search_Indexer_console.log
  * @return array
  */
 function rebuild($loggit = 0)
 {
     global $prefs;
     $errlib = TikiLib::lib('errorreport');
     switch ($prefs['unified_engine']) {
         case 'lucene':
             $index_location = $this->getIndexLocation('data');
             $tempName = $this->getIndexLocation('data-new');
             $swapName = $this->getIndexLocation('data-old');
             if ($this->rebuildInProgress()) {
                 $errlib->report(tr('Rebuild in progress.'));
                 return false;
             }
             $index = new Search_Lucene_Index($tempName);
             TikiLib::events()->bind('tiki.process.shutdown', function () use($index) {
                 if ($index->exists()) {
                     $index->destroy();
                     echo "Abnormal termination. Unless it was killed manually, it likely ran out of memory.\n";
                 }
             });
             break;
         case 'elastic':
             $connection = $this->getElasticConnection(true);
             $aliasName = $prefs['unified_elastic_index_prefix'] . 'main';
             $indexName = $aliasName . '_' . uniqid();
             $index = new Search_Elastic_Index($connection, $indexName);
             $index->setCamelCaseEnabled($prefs['unified_elastic_camel_case'] == 'y');
             TikiLib::events()->bind('tiki.process.shutdown', function () use($indexName, $index) {
                 global $prefs;
                 if ($prefs['unified_elastic_index_current'] !== $indexName) {
                     $index->destroy();
                 }
             });
             break;
         case 'mysql':
             $indexName = 'index_' . uniqid();
             $index = new Search_MySql_Index(TikiDb::get(), $indexName);
             TikiLib::events()->bind('tiki.process.shutdown', function () use($indexName, $index) {
                 global $prefs;
                 if ($prefs['unified_mysql_index_current'] !== $indexName) {
                     $index->destroy();
                 }
             });
             break;
         default:
             die('Unsupported');
     }
     // Build in -new
     TikiLib::lib('queue')->clear(self::INCREMENT_QUEUE);
     $tikilib = TikiLib::lib('tiki');
     $access = TikiLib::lib('access');
     $access->preventRedirect(true);
     $this->isRebuildingNow = true;
     $stat = array();
     $indexer = null;
     try {
         $index = new Search_Index_TypeAnalysisDecorator($index);
         $indexer = $this->buildIndexer($index, $loggit);
         $stat = $tikilib->allocate_extra('unified_rebuild', function () use($indexer) {
             return $indexer->rebuild();
         });
         $tikilib->set_preference('unified_identifier_fields', $index->getIdentifierFields());
     } catch (Exception $e) {
         $errlib->report(tr('Search index could not be rebuilt.') . '<br />' . $e->getMessage());
     }
     // Force destruction to clear locks
     if ($indexer) {
         $indexer->clearSources();
         unset($indexer);
     }
     unset($index);
     $oldIndex = null;
     switch ($prefs['unified_engine']) {
         case 'lucene':
             // Current to -old
             if (file_exists($index_location)) {
                 if (!rename($index_location, $swapName)) {
                     $errlib->report(tr('Could not remove active index. Likely a file permission issue.'));
                 }
             }
             // -new to current
             if (!rename($tempName, $index_location)) {
                 $errlib->report(tr('Could not transfer new index to active. Likely a file permission issue.'));
             }
             // Destroy old
             $oldIndex = new Search_Lucene_Index($swapName);
             break;
         case 'elastic':
             $oldIndex = null;
             // assignAlias will handle the clean-up
             $tikilib->set_preference('unified_elastic_index_current', $indexName);
             $connection->assignAlias($aliasName, $indexName);
             break;
         case 'mysql':
             // Obtain the old index and destroy it after permanently replacing it.
             $oldIndex = $this->getIndex('data');
             $tikilib->set_preference('unified_mysql_index_current', $indexName);
             break;
     }
     if ($oldIndex) {
         if (!$oldIndex->destroy()) {
             $errlib->report(tr('Failed to destroy the old index.'));
         }
     }
     // Process the documents updated while we were processing the update
     $this->processUpdateQueue(1000);
     if ($prefs['storedsearch_enabled'] == 'y') {
         TikiLib::lib('storedsearch')->reloadAll();
     }
     $tikilib->set_preference('unified_last_rebuild', $tikilib->now);
     $this->isRebuildingNow = false;
     $access->preventRedirect(false);
     return $stat;
 }
Пример #3
0
 /**
  * @param bool $loggit
  * @return array
  */
 function rebuild($loggit = false)
 {
     global $prefs;
     $errlib = TikiLib::lib('errorreport');
     switch ($prefs['unified_engine']) {
         case 'lucene':
             $index_location = $this->getIndexLocation();
             $tempName = $index_location . '-new';
             $swapName = $index_location . '-old';
             if ($this->rebuildInProgress()) {
                 $errlib->report(tr('Rebuild in progress.'));
                 return false;
             }
             $index = new Search_Index_Lucene($tempName);
             $unifiedsearchlib = $this;
             register_shutdown_function(function () use($tempName, $unifiedsearchlib) {
                 if (file_exists($tempName)) {
                     $unifiedsearchlib->destroyDirectory($tempName);
                     echo "Abnormal termination. Unless it was killed manually, it likely ran out of memory.\n";
                 }
             });
             break;
         case 'elastic':
             $connection = $this->getElasticConnection();
             $indexName = $prefs['unified_elastic_index_prefix'] . uniqid();
             $index = new Search_Elastic_Index($connection, $indexName);
             register_shutdown_function(function () use($indexName, $index) {
                 global $prefs;
                 if ($prefs['unified_elastic_index_current'] !== $indexName) {
                     $index->destroy();
                 }
             });
             break;
         default:
             die('Unsupported');
     }
     // Build in -new
     TikiLib::lib('queue')->clear(self::INCREMENT_QUEUE);
     $tikilib = TikiLib::lib('tiki');
     $access = TikiLib::lib('access');
     $access->preventRedirect(true);
     $index = new Search_Index_TypeAnalysisDecorator($index);
     $indexer = $this->buildIndexer($index, $loggit);
     $stat = $tikilib->allocate_extra('unified_rebuild', function () use($indexer) {
         return $indexer->rebuild();
     });
     $access->preventRedirect(false);
     $tikilib->set_preference('unified_identifier_fields', $index->getIdentifierFields());
     // Force destruction to clear locks
     unset($indexer);
     unset($index);
     switch ($prefs['unified_engine']) {
         case 'lucene':
             // Current to -old
             if (file_exists($index_location)) {
                 if (!rename($index_location, $swapName)) {
                     $errlib->report(tr('Could not remove active index. Likely a file permission issue.'));
                 }
             }
             // -new to current
             if (!rename($tempName, $index_location)) {
                 $errlib->report(tr('Could not transfer new index to active. Likely a file permission issue.'));
             }
             // Destroy old
             $this->destroyDirectory($swapName);
             if (file_exists($swapName)) {
                 $errlib->report(tr('Failed to destroy the old index. Likely a file permission issue.'));
             }
             break;
         case 'elastic':
             // Obtain the old index and destroy it after permanently replacing it.
             $oldIndex = $this->getIndex();
             $tikilib->set_preference('unified_elastic_index_current', $indexName);
             if ($oldIndex) {
                 $oldIndex->destroy();
             }
             break;
     }
     // Process the documents updated while we were processing the update
     $this->processUpdateQueue(1000);
     $tikilib->set_preference('unified_last_rebuild', $tikilib->now);
     return $stat;
 }