本文整理匯總了PHP中Indexer::clear方法的典型用法代碼示例。如果您正苦於以下問題:PHP Indexer::clear方法的具體用法?PHP Indexer::clear怎麽用?PHP Indexer::clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Indexer
的用法示例。
在下文中一共展示了Indexer::clear方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testClear
public function testClear()
{
update_option('fields', array('field1' => 1, 'field2' => 1));
register_post_type('post');
Indexer::addOrUpdate((object) array('post_type' => 'post', 'ID' => 1, 'field1' => 'value1', 'field2' => 'value2'));
$this->index->refresh();
$this->assertEquals(1, $this->index->count());
Indexer::clear();
$this->index->refresh();
$this->assertEquals(0, $this->index->count());
}
示例2: add_filter
});
add_filter('nhp-opts-saved-text-elasticsearch', function ($default) {
if (get_transient('es-wiped') == 1) {
return '<strong>The index has been wiped.</strong>';
delete_transient('es-wiped');
}
if (get_transient('es-indexed') == 1) {
return '<strong>The index has been populated.</strong>';
delete_transient('es-indexed');
}
return $default;
});
add_action('nhp-opts-options-validate-elasticsearch', function () {
if (isset($_POST['wipe']) && $_POST['wipe']) {
try {
Indexer::clear();
set_transient('es-wiped', 1, 30);
} catch (\Exception $ex) {
$errors = get_transient('nhp-opts-errors-elasticsearch');
$errors[] = array('section_id' => 'index');
set_transient('nhp-opts-errors-elasticsearch', $errors, 1000);
set_transient('es-wiped-error', $ex->getMessage(), 30);
}
}
});
ob_start();
?>
<div style="font-size: 12px; font-style: normal">
<table class="form-table">
<tbody>
示例3: index
public function index($domain)
{
$indexer = new Indexer($this->getAccountId($domain));
$indexer->clear();
$indexer->index();
}
示例4: testSearchPaging
public function testSearchPaging()
{
update_option('fields', array('field1' => 1));
update_option('score_field_field1', 1);
register_post_type('post');
Indexer::clear();
Indexer::addOrUpdate((object) array('post_type' => 'post', 'ID' => 1, 'post_date' => '10/24/1988 00:00:00 CST', 'field1' => 'value1'));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'ID' => 2, 'post_date' => '10/21/1988 00:00:00 CST', 'field1' => 'value1'));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'ID' => 3, 'post_date' => '10/20/1988 00:00:00 CST', 'field1' => 'value1'));
$this->index->refresh();
$results = $this->searcher->search('value1', 0, 1);
$this->assertEquals(3, $results['total']);
$first = $results['ids'][0];
$results = $this->searcher->search('value1', 1, 1);
$this->assertEquals(3, $results['total']);
$second = $results['ids'][0];
$this->assertTrue($second != $first);
$results = $this->searcher->search('value1', 2, 1);
$this->assertEquals(3, $results['total']);
$this->assertTrue($results['ids'][0] != $first && $results['ids'][0] != $second);
}
示例5: testNotAnalyzed
public function testNotAnalyzed()
{
update_option('fields', array('field1' => 1));
update_option('not_analyzed', array('field1' => 1));
update_option('score_field_field1', 1);
register_post_type('post');
Indexer::clear();
Indexer::addOrUpdate((object) array('post_type' => 'post', 'ID' => 1, 'post_date' => '10/24/1988 00:00:00 CST', 'field1' => 'foo bar'));
$this->index->refresh();
$results = $this->searcher->search('foo');
$this->assertEquals(0, $results['total']);
$this->assertEquals(array(), $results['ids']);
$results = $this->searcher->search('foo bar');
$this->assertEquals(0, $results['total']);
$this->assertEquals(array(), $results['ids']);
$results = $this->searcher->search('"foo bar"');
$this->assertEquals(1, $results['total']);
$this->assertEquals(array(1), $results['ids']);
}