本文整理汇总了PHP中Indexer::addOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP Indexer::addOrUpdate方法的具体用法?PHP Indexer::addOrUpdate怎么用?PHP Indexer::addOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Indexer
的用法示例。
在下文中一共展示了Indexer::addOrUpdate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDelete
public function testDelete()
{
update_option('fields', array('field1' => 1, 'field2' => 1));
register_post_type('post');
$post = (object) array('post_type' => 'post', 'ID' => 1, 'field1' => 'value1', 'field2' => 'value2');
Indexer::addOrUpdate($post);
$this->index->refresh();
$this->assertEquals(1, $this->index->count(new \Elastica\Query(array('query' => array('bool' => array('must' => array(array('match' => array('_id' => 1)), array('match' => array('field1' => 'value1')), array('match' => array('field2' => 'value2')))))))));
Indexer::delete($post);
$this->index->refresh();
$this->assertEquals(0, $this->index->count());
}
示例2: save_post
function save_post($post_id)
{
if (is_object($post_id)) {
$post = $post_id;
} else {
$post = get_post($post_id);
}
if ($post == null || !in_array($post->post_type, Config::types())) {
return;
}
if ($post->post_status == 'publish') {
Indexer::addOrUpdate($post);
} else {
Indexer::delete($post);
}
}
示例3: testSearchRangeLadderDown
public function testSearchRangeLadderDown()
{
update_option('numeric', array('field1' => 1));
update_option('fields', array('field1' => 1));
update_option('field1_range', '-30,-20,-10');
register_post_type('post');
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 1, 'field1' => 5));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 2, 'field1' => 15));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 3, 'field1' => 17));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 4, 'field1' => 23));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 5, 'field1' => 25));
Indexer::addOrUpdate((object) array('post_type' => 'post', 'post_date' => '10/24/1988 00:00:00 CST', 'ID' => 6, 'field1' => 27));
$this->index->refresh();
$results = $this->searcher->search(null, 0, 10, array('field1' => '-30'));
$this->assertEquals(6, $results['total']);
$this->assertEquals(0, count(array_diff(array(4, 5, 1, 6, 2, 3), $results['ids'])));
$this->assertEquals(array('field1' => array('-10' => 1, '-20' => 3, '-30' => 6)), $results['facets']);
$results = $this->searcher->search(null, 0, 10, array('field1' => '-20'));
$this->assertEquals(3, $results['total']);
$this->assertEquals(0, count(array_diff(array(1, 2, 3), $results['ids'])));
$this->assertEquals(array('field1' => array('-10' => 1, '-20' => 3, '-30' => 3)), $results['facets']);
$results = $this->searcher->search(null, 0, 10, array('field1' => '-10'));
$this->assertEquals(1, $results['total']);
$this->assertEquals(0, count(array_diff(array(1), $results['ids'])));
$this->assertEquals(array('field1' => array('-10' => 1, '-20' => 1, '-30' => 1)), $results['facets']);
}