本文整理汇总了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']);
}