Inheritance: extends XmlWebService
コード例 #1
0
ファイル: LucenePlugin.inc.php プロジェクト: yuricampos/ojs
 /**
  * @see ArticleSearchIndex::rebuildIndex()
  */
 function callbackRebuildIndex($hookName, $params)
 {
     assert($hookName == 'ArticleSearchIndex::rebuildIndex');
     $solrWebService = $this->getSolrWebService();
     // Unpack the parameters.
     list($log, $journal) = $params;
     // If we got a journal instance then only re-index
     // articles from that journal.
     $journalIdOrNull = is_a($journal, 'Journal') ? $journal->getId() : null;
     // Clear index (if the journal id is null then
     // all journals will be deleted from the index).
     if ($log) {
         echo 'LucenePlugin: ' . __('search.cli.rebuildIndex.clearingIndex') . ' ... ';
     }
     $solrWebService->deleteArticlesFromIndex($journalIdOrNull);
     if ($log) {
         echo __('search.cli.rebuildIndex.done') . "\n";
     }
     // Re-build index, either of a single journal...
     if (is_a($journal, 'Journal')) {
         $journals = array($journal);
         unset($journal);
         // ...or for all journals.
     } else {
         $journalDao =& DAORegistry::getDAO('JournalDAO');
         /* @var $journalDao JournalDAO */
         $journalIterator =& $journalDao->getJournals();
         $journals = $journalIterator->toArray();
     }
     // We re-index journal by journal to partition the task a bit
     // and provide better progress information to the user.
     foreach ($journals as $journal) {
         if ($log) {
             echo __('search.cli.rebuildIndex.indexing', array('journalName' => $journal->getLocalizedTitle())) . ' ';
         }
         // Mark all articles in the journal for re-indexing.
         $numMarked = $this->_solrWebService->markJournalChanged($journal->getId());
         // Pull or push?
         if ($this->getSetting(0, 'pullIndexing')) {
             // When pull-indexing is configured then we leave it up to the
             // Solr server to decide when the updates will actually be done.
             if ($log) {
                 echo '... ' . __('plugins.generic.lucene.rebuildIndex.pullResult', array('numMarked' => $numMarked)) . "\n";
             }
         } else {
             // In case of push indexing we immediately update the index.
             $numIndexed = 0;
             do {
                 // We update the index in batches to reduce max memory usage
                 // and make a few intermediate commits.
                 $articlesInBatch = $solrWebService->pushChangedArticles(SOLR_INDEXING_MAX_BATCHSIZE, $journal->getId());
                 if (is_null($articlesInBatch)) {
                     $error = $solrWebService->getServiceMessage();
                     if ($log) {
                         echo ' ' . __('search.cli.rebuildIndex.error') . (empty($error) ? '' : ": {$error}") . "\n";
                     } else {
                         $this->_informTechAdmin($error, $journal);
                     }
                     return false;
                 }
                 if ($log) {
                     echo '.';
                 }
                 $numIndexed += $articlesInBatch;
             } while ($articlesInBatch == SOLR_INDEXING_MAX_BATCHSIZE);
             if ($log) {
                 echo ' ' . __('search.cli.rebuildIndex.result', array('numIndexed' => $numIndexed)) . "\n";
             }
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Start the solr server and wait for it to
  * become online.
  * @param $embeddedServer EmbeddedServer
  */
 private function startSolrServer($embeddedServer)
 {
     $embeddedServer->start();
     import('plugins.generic.lucene.classes.SolrWebService');
     $solrWebService = new SolrWebService('http://localhost:8983/solr/ojs/search', 'admin', 'please change', 'test-inst');
     $try = 0;
     while ($solrWebService->getServerStatus() == SOLR_STATUS_OFFLINE && $try <= 10) {
         sleep(1);
         $try++;
     }
     self::assertEquals(SOLR_STATUS_ONLINE, $solrWebService->getServerStatus());
 }
コード例 #3
0
ファイル: LucenePlugin.inc.php プロジェクト: stweil/ojs
 /**
  * Rebuild the index for all journals or a single journal
  * @param $log boolean Whether to write the log to standard output.
  * @param $journal Journal If given, only re-index this journal.
  * @param $buildIndex boolean Whether to rebuild the journal index.
  * @param $buildDictionaries boolean Whether to rebuild dictionaries.
  * @param $messages string Return parameter for log message output.
  * @return boolean True on success, otherwise false.
  */
 function _rebuildIndex($log, $journal, $buildIndex, $buildDictionaries, $updateBoostFile, &$messages)
 {
     // Rebuilding the index can take a long time.
     @set_time_limit(0);
     $solrWebService = $this->getSolrWebService();
     if ($buildIndex) {
         // If we got a journal instance then only re-index
         // articles from that journal.
         $journalIdOrNull = is_a($journal, 'Journal') ? $journal->getId() : null;
         // Clear index (if the journal id is null then
         // all journals will be deleted from the index).
         $this->_indexingMessage($log, 'LucenePlugin: ' . __('search.cli.rebuildIndex.clearingIndex') . ' ... ', $messages);
         $solrWebService->deleteArticlesFromIndex($journalIdOrNull);
         $this->_indexingMessage($log, __('search.cli.rebuildIndex.done') . PHP_EOL, $messages);
         // Re-build index, either of a single journal...
         if (is_a($journal, 'Journal')) {
             $journals = array($journal);
             unset($journal);
             // ...or for all journals.
         } else {
             $journalDao = DAORegistry::getDAO('JournalDAO');
             /* @var $journalDao JournalDAO */
             $journalIterator = $journalDao->getAll();
             $journals = $journalIterator->toArray();
         }
         // We re-index journal by journal to partition the task a bit
         // and provide better progress information to the user.
         foreach ($journals as $journal) {
             $this->_indexingMessage($log, 'LucenePlugin: ' . __('search.cli.rebuildIndex.indexing', array('journalName' => $journal->getLocalizedName())) . ' ', $messages);
             // Mark all articles in the journal for re-indexing.
             $numMarked = $this->_solrWebService->markJournalChanged($journal->getId());
             // Pull or push?
             if ($this->getSetting(0, 'pullIndexing')) {
                 // When pull-indexing is configured then we leave it up to the
                 // Solr server to decide when the updates will actually be done.
                 $this->_indexingMessage($log, '... ' . __('plugins.generic.lucene.rebuildIndex.pullResult', array('numMarked' => $numMarked)) . PHP_EOL, $messages);
             } else {
                 // In case of push indexing we immediately update the index.
                 $numIndexed = 0;
                 do {
                     // We update the index in batches to reduce max memory usage
                     // and make a few intermediate commits.
                     $articlesInBatch = $solrWebService->pushChangedArticles(SOLR_INDEXING_MAX_BATCHSIZE, $journal->getId());
                     if (is_null($articlesInBatch)) {
                         $error = $solrWebService->getServiceMessage();
                         $this->_indexingMessage($log, ' ' . __('search.cli.rebuildIndex.error') . (empty($error) ? '' : ": {$error}") . PHP_EOL, $messages);
                         if (!$log) {
                             // If logging is switched off then inform the
                             // tech admin with an email (e.g. in the case of
                             // an OJS upgrade).
                             $this->_informTechAdmin($error, $journal);
                         }
                         return true;
                     }
                     $this->_indexingMessage($log, '.', $messages);
                     $numIndexed += $articlesInBatch;
                 } while ($articlesInBatch == SOLR_INDEXING_MAX_BATCHSIZE);
                 $this->_indexingMessage($log, ' ' . __('search.cli.rebuildIndex.result', array('numIndexed' => $numIndexed)) . PHP_EOL, $messages);
             }
         }
     }
     if ($buildDictionaries) {
         // Rebuild dictionaries.
         $this->_indexingMessage($log, 'LucenePlugin: ' . __('plugins.generic.lucene.rebuildIndex.rebuildDictionaries') . ' ... ', $messages);
         $solrWebService->rebuildDictionaries();
         if ($updateBoostFile) {
             $this->_indexingMessage($log, __('search.cli.rebuildIndex.done') . PHP_EOL, $messages);
         }
     }
     // Remove the field cache file as additional fields may be available after re-indexing. If we don't
     // do this it may seem that indexing didn't work as the cache will only be invalidated after 24 hours.
     $cacheFile = 'cache/fc-plugins-lucene-fieldCache.php';
     if (file_exists($cacheFile)) {
         if (is_writable(dirname($cacheFile))) {
             unlink($cacheFile);
         } else {
             $this->_indexingMessage($log, 'LucenePlugin: ' . __('plugins.generic.lucene.rebuildIndex.couldNotDeleteFieldCache') . PHP_EOL, $messages);
         }
     }
     if ($updateBoostFile) {
         // Update the boost file.
         $this->_indexingMessage($log, 'LucenePlugin: ' . __('plugins.generic.lucene.rebuildIndex.updateBoostFile') . ' ... ', $messages);
         $this->_updateBoostFiles();
     }
     $this->_indexingMessage($log, __('search.cli.rebuildIndex.done') . PHP_EOL, $messages);
     return true;
 }
コード例 #4
0
ファイル: SolrWebServiceTest.php プロジェクト: jalperin/ojs
 /**
  * Check that the given article is not indexed.
  * @param $articleId integer
  */
 private function articleNotInIndex($articleId)
 {
     $article = $this->solrWebService->getArticleFromIndex($articleId);
     self::assertTrue(empty($article));
 }