本文整理汇总了PHP中FinderIndexer::getState方法的典型用法代码示例。如果您正苦于以下问题:PHP FinderIndexer::getState方法的具体用法?PHP FinderIndexer::getState怎么用?PHP FinderIndexer::getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FinderIndexer
的用法示例。
在下文中一共展示了FinderIndexer::getState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetState
/**
* Tests the setState method
*
* @return void
*
* @since 3.0
*/
public function testSetState()
{
// Set up our test object
$test = new JObject();
$test->string = 'Testing FinderIndexer::setState()';
// First, assert we can successfully set the state
$this->assertTrue(FinderIndexer::setState($test));
// Set the session data to test retrieval
FinderIndexer::setState($test);
// Now assert we can successfully get the state data we just stored
$this->assertInstanceOf('JObject', FinderIndexer::getState());
}
示例2: createIndexes
public function createIndexes(InputInterface $input, OutputInterface $output)
{
$output->writeln(\JText::_('FINDER_CLI_INDEX_PURGE'));
require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
// Initialize the time value.
$this->time = microtime(true);
// Remove the script time limit.
@set_time_limit(0);
$_SERVER['HTTP_HOST'] = 'domain.com';
// Disable caching.
$config = \JFactory::getConfig();
$config->set('caching', 0);
$config->set('cache_handler', 'file');
// Reset the indexer state.
\FinderIndexer::resetState();
// Import the finder plugins.
\JPluginHelper::importPlugin('finder');
// Starting Indexer.
$output->writeln(\JText::_('FINDER_CLI_STARTING_INDEXER'));
// Trigger the onStartIndex event.
\JEventDispatcher::getInstance()->trigger('onStartIndex');
// Remove the script time limit.
@set_time_limit(0);
// Get the indexer state.
$state = \FinderIndexer::getState();
// Setting up plugins.
$output->writeln(\JText::_('FINDER_CLI_SETTING_UP_PLUGINS'));
// Trigger the onBeforeIndex event.
\JEventDispatcher::getInstance()->trigger('onBeforeIndex');
// Startup reporting.
$output->writeln(\JText::sprintf('FINDER_CLI_SETUP_ITEMS', $state->totalItems, round(microtime(true) - $this->time, 3)), true);
// Get the number of batches.
$t = (int) $state->totalItems;
$c = (int) ceil($t / $state->batchSize);
$c = $c === 0 ? 1 : $c;
try {
// Process the batches.
for ($i = 0; $i < $c; $i++) {
// Set the batch start time.
$this->qtime = microtime(true);
// Reset the batch offset.
$state->batchOffset = 0;
// Trigger the onBuildIndex event.
\JEventDispatcher::getInstance()->trigger('onBuildIndex');
// Batch reporting.
$output->writeln("<info>" . \JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->qtime, 3)) . "</info>");
}
} catch (Exception $e) {
// Reset the indexer state.
\FinderIndexer::resetState();
throw new \RuntimeException($e->getMessage());
}
// Reset the indexer state.
\FinderIndexer::resetState();
}
示例3: optimize
/**
* Method to optimize the index and perform any necessary cleanup.
*
* @return void
*
* @since 2.5
*/
public function optimize()
{
// We don't want this form to be cached.
header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Expires: -1');
// Check for a valid token. If invalid, send a 403 with the error message.
JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
// Put in a buffer to silence noise.
ob_start();
// Import the finder plugins.
JPluginHelper::importPlugin('finder');
try {
// Optimize the index
FinderIndexer::getInstance()->optimize();
// Get the indexer state.
$state = FinderIndexer::getState();
$state->start = 0;
$state->complete = 1;
// Send the response.
$this->sendResponse($state);
} catch (Exception $e) {
$this->sendResponse($e);
}
}
示例4: _index
/**
* Run the indexer
*
* @return void
*
* @since 2.5
*/
private function _index()
{
// initialize the time value
$this->_time = microtime(true);
// import library dependencies
require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
jimport('joomla.application.component.helper');
// fool the system into thinking we are running as JSite with Finder as the active component
JFactory::getApplication('site');
$_SERVER['HTTP_HOST'] = 'domain.com';
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_finder');
// Disable caching.
$config = JFactory::getConfig();
$config->set('caching', 0);
$config->set('cache_handler', 'file');
// Reset the indexer state.
FinderIndexer::resetState();
// Import the finder plugins.
JPluginHelper::importPlugin('finder');
// Starting Indexer.
$this->out(JText::_('FINDER_CLI_STARTING_INDEXER'), true);
// Trigger the onStartIndex event.
JDispatcher::getInstance()->trigger('onStartIndex');
// Remove the script time limit.
@set_time_limit(0);
// Get the indexer state.
$state = FinderIndexer::getState();
// Setting up plugins.
$this->out(JText::_('FINDER_CLI_SETTING_UP_PLUGINS'), true);
// Trigger the onBeforeIndex event.
JDispatcher::getInstance()->trigger('onBeforeIndex');
// Startup reporting.
$this->out(JText::sprintf('FINDER_CLI_SETUP_ITEMS', $state->totalItems, round(microtime(true) - $this->_time, 3)), true);
// Get the number of batches.
$t = (int) $state->totalItems;
$c = (int) ceil($t / $state->batchSize);
$c = $c === 0 ? 1 : $c;
// Process the batches.
for ($i = 0; $i < $c; $i++) {
// Set the batch start time.
$this->_qtime = microtime(true);
// Reset the batch offset.
$state->batchOffset = 0;
// Trigger the onBuildIndex event.
JDispatcher::getInstance()->trigger('onBuildIndex');
// Batch reporting.
$this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->_qtime, 3)), true);
}
// Total reporting.
$this->out(JText::sprintf('FINDER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->_time, 3)), true);
// Reset the indexer state.
FinderIndexer::resetState();
}
示例5: onBuildIndex
/**
* Method to index a batch of content items. This method can be called by
* the indexer many times throughout the indexing process depending on how
* much content is available for indexing. It is important to track the
* progress correctly so we can display it to the user.
*
* @return boolean True on success.
*
* @since 2.5
* @throws Exception on error.
*/
public function onBuildIndex()
{
// Get the indexer and adapter state.
$iState = FinderIndexer::getState();
$aState = $iState->pluginState[$this->context];
// Check the progress of the indexer and the adapter.
if ($iState->batchOffset == $iState->batchSize || $aState['offset'] == $aState['total']) {
return true;
}
// Get the batch offset and size.
$offset = (int) $aState['offset'];
$limit = (int) ($iState->batchSize - $iState->batchOffset);
// Get the content items to index.
$items = $this->getItems($offset, $limit);
// Iterate through the items and index them.
for ($i = 0, $n = count($items); $i < $n; $i++) {
// Index the item.
$this->index($items[$i]);
// Adjust the offsets.
$offset++;
$iState->batchOffset++;
$iState->totalItems--;
}
// Update the indexer state.
$aState['offset'] = $offset;
$iState->pluginState[$this->context] = $aState;
FinderIndexer::setState($iState);
return true;
}
示例6: index
/**
* Run the indexer.
*
* @return void
*
* @since 2.5
*/
private function index()
{
require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/indexer.php';
// Disable caching.
$config = JFactory::getConfig();
$config->set('caching', 0);
$config->set('cache_handler', 'file');
// Reset the indexer state.
FinderIndexer::resetState();
// Import the finder plugins.
JPluginHelper::importPlugin('finder');
// Starting Indexer.
$this->out(JText::_('FINDER_CLI_STARTING_INDEXER'), true);
// Trigger the onStartIndex event.
JFactory::getApplication()->triggerEvent('onStartIndex');
// Remove the script time limit.
@set_time_limit(0);
// Get the indexer state.
$state = FinderIndexer::getState();
// Setting up plugins.
$this->out(JText::_('FINDER_CLI_SETTING_UP_PLUGINS'), true);
// Trigger the onBeforeIndex event.
JFactory::getApplication()->triggerEvent('onBeforeIndex');
// Startup reporting.
$this->out(JText::sprintf('FINDER_CLI_SETUP_ITEMS', $state->totalItems, round(microtime(true) - $this->time, 3)), true);
// Get the number of batches.
$t = (int) $state->totalItems;
$c = (int) ceil($t / $state->batchSize);
$c = $c === 0 ? 1 : $c;
try {
// Process the batches.
for ($i = 0; $i < $c; $i++) {
// Set the batch start time.
$this->qtime = microtime(true);
// Reset the batch offset.
$state->batchOffset = 0;
// Trigger the onBuildIndex event.
JFactory::getApplication()->triggerEvent('onBuildIndex');
// Batch reporting.
$this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->qtime, 3)), true);
}
} catch (Exception $e) {
// Display the error
$this->out($e->getMessage(), true);
// Reset the indexer state.
FinderIndexer::resetState();
// Close the app
$this->close($e->getCode());
}
// Reset the indexer state.
FinderIndexer::resetState();
}
示例7: testSetState
/**
* Tests the setState method
*
* @return void
*
* @since 3.0
*/
public function testSetState()
{
// Override the database in this method
$this->saveFactoryDatabase();
// Set up our test object
$test = new JObject();
$test->string = 'Testing FinderIndexer::setState()';
// First, assert we can successfully set the state
$this->assertThat(FinderIndexer::setState($test), $this->isTrue());
// Set the session data to test retrieval
FinderIndexer::setState($test);
// Now assert we can successfully get the state data we just stored
$this->assertThat(FinderIndexer::getState(), $this->isInstanceOf('JObject'));
// Restore the database
$this->restoreFactoryDatabase();
}
示例8: getSignature
/**
* Method to get a content item's signature.
*
* @param object $item The content item to index.
*
* @return string The content item's signature.
*
* @since 2.5
*/
protected static function getSignature($item)
{
// Get the indexer state.
$state = FinderIndexer::getState();
// Get the relevant configuration variables.
$config = array();
$config[] = $state->weights;
$config[] = $state->options->get('stem', 1);
$config[] = $state->options->get('stemmer', 'porter_en');
return md5(serialize(array($item, $config)));
}
示例9: onBuildIndex
/**
* Method to index a batch of content items. This method can be called by
* the indexer many times throughout the indexing process depending on how
* much content is available for indexing. It is important to track the
* progress correctly so we can display it to the user.
*
* @return boolean True on success.
*
* @since 2.5
* @throws Exception on error.
*/
public function onBuildIndex()
{
JLog::add('FinderIndexerAdapter::onBuildIndex', JLog::INFO);
// Get the indexer and adapter state.
$iState = FinderIndexer::getState();
$aState = $iState->pluginState[$this->context];
// Check the progress of the indexer and the adapter.
if ($iState->batchOffset == $iState->batchSize || $aState['offset'] == $aState['total']) {
return true;
}
// Get the batch offset and size.
$offset = (int) $aState['offset'];
$limit = (int) ($iState->batchSize - $iState->batchOffset);
// Get the content items to index.
$items = $this->getItems($offset, $limit);
// Iterate through the items and index them.
$item = null;
foreach ($items as $item) {
$this->index($item);
}
if ($item) {
// Adjust the offsets.
$iState->batchOffset = $iState->batchSize;
$iState->totalItems -= $item->id - $offset;
// Update the indexer state.
$aState['offset'] = $item->id;
$iState->pluginState[$this->context] = $aState;
FinderIndexer::setState($iState);
}
unset($items, $item);
return true;
}
示例10: optimize
/**
* Method to optimize the index and perform any necessary cleanup.
*
* @return void
*
* @since 2.5
*/
public function optimize()
{
// We don't want this form to be cached.
$app = JFactory::getApplication();
$app->setHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true);
$app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
$app->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
$app->setHeader('Pragma', 'no-cache');
// Check for a valid token. If invalid, send a 403 with the error message.
JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
// Put in a buffer to silence noise.
ob_start();
// Import the finder plugins.
JPluginHelper::importPlugin('finder');
try {
// Optimize the index
FinderIndexer::getInstance()->optimize();
// Get the indexer state.
$state = FinderIndexer::getState();
$state->start = 0;
$state->complete = 1;
// Send the response.
$this->sendResponse($state);
} catch (Exception $e) {
$this->sendResponse($e);
}
}