本文整理汇总了PHP中FinderIndexer::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP FinderIndexer::getInstance方法的具体用法?PHP FinderIndexer::getInstance怎么用?PHP FinderIndexer::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FinderIndexer
的用法示例。
在下文中一共展示了FinderIndexer::getInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: testGetInstanceException
/**
* Tests the getInstance method
*
* @return void
*
* @since 3.0
* @expectedException RuntimeException
*/
public function testGetInstanceException()
{
JFactory::$database->name = 'nosql';
FinderIndexer::getInstance();
}
示例3: index
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) == false) {
return;
}
// Initialize the item parameters.
$registry = new JRegistry();
$registry->loadString($item->params);
$item->params = JComponentHelper::getParams('com_k2', true);
$item->params->merge($registry);
$registry = new JRegistry();
$registry->loadString($item->metadata);
$item->metadata = $registry;
// Trigger the onContentPrepare event.
$item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params);
$item->body = FinderIndexerHelper::prepareContent($item->body, $item->params);
// Build the necessary route and path information.
$item->url = $this->getURL($item->id, $this->extension, $this->layout);
$item->route = K2HelperRoute::getItemRoute($item->slug, $item->catslug);
$item->path = FinderIndexerHelper::getContentPath($item->route);
// Get the menu title if it exists.
$title = $this->getItemMenuTitle($item->url);
// Adjust the title if necessary.
if (!empty($title) && $this->params->get('use_menu_title', true)) {
$item->title = $title;
}
// Add the meta-author.
$item->metaauthor = $item->metadata->get('author');
// Add the meta-data processing instructions.
$item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey');
$item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc');
$item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor');
$item->addInstruction(FinderIndexer::META_CONTEXT, 'author');
$item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias');
// Translate the state. Articles should only be published if the category is published.
$item->state = $this->translateState($item->state, $item->cat_state);
// Translate the trash state. Articles should only be accesible if the category is accessible.
if ($item->trash || $item->cat_trash) {
$item->state = 0;
}
// Add the type taxonomy data.
$item->addTaxonomy('Type', 'K2 Item');
// Add the author taxonomy data.
if (!empty($item->author) || !empty($item->created_by_alias)) {
$item->addTaxonomy('Author', !empty($item->created_by_alias) ? $item->created_by_alias : $item->author);
}
// Add the category taxonomy data.
$item->addTaxonomy('K2 Category', $item->category, $item->cat_state, $item->cat_access);
// Add the language taxonomy data.
$item->addTaxonomy('Language', $item->language);
// Get content extras.
FinderIndexerHelper::getContentExtras($item);
// Index the item.
if (method_exists('FinderIndexer', 'getInstance')) {
FinderIndexer::getInstance()->index($item);
} else {
FinderIndexer::index($item);
}
}
示例4: __construct
/**
* Method to instantiate the indexer adapter.
*
* @param object &$subject The object to observe.
* @param array $config An array that holds the plugin configuration.
*
* @since 2.5
*/
public function __construct(&$subject, $config)
{
// Get the database object.
$this->db = JFactory::getDbo();
// Call the parent constructor.
parent::__construct($subject, $config);
// Get the type id.
$this->type_id = $this->getTypeId();
// Add the content type if it doesn't exist and is set.
if (empty($this->type_id) && !empty($this->type_title)) {
$this->type_id = FinderIndexerHelper::addContentType($this->type_title, $this->mime);
}
// Check for a layout override.
if ($this->params->get('layout')) {
$this->layout = $this->params->get('layout');
}
// Get the indexer object
$this->indexer = FinderIndexer::getInstance();
}
示例5: testGetInstanceException
/**
* Tests the getInstance method
*
* @return void
*
* @since 3.0
*/
public function testGetInstanceException()
{
// Override the database in this method
$this->saveFactoryDatabase();
JFactory::$database->name = 'nosql';
$this->setExpectedException('RuntimeException');
FinderIndexer::getInstance();
// Restore the database
$this->restoreFactoryDatabase();
}
示例6: 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);
}
}
示例7: index
/**
* Main index function run when indexing happens
*
* @param FinderIndexerResult $item
* @return bool|void
*/
protected function index(FinderIndexerResult $item)
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) == false) {
return;
}
//Add the instructions
foreach ($this->instructions as $type => $instructions) {
foreach ($instructions as $instruction) {
$item->addInstruction($type, $instruction);
}
}
// Add the type taxonomy data.
$item->addTaxonomy('Type', $this->type_title);
FinderIndexerHelper::getContentExtras($item);
// Index the item.
if (method_exists('FinderIndexer', 'getInstance')) {
FinderIndexer::getInstance()->index($item);
} else {
FinderIndexer::index($item);
}
}