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());
 }
});
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>
Beispiel #3
0
 public function index($domain)
 {
     $indexer = new Indexer($this->getAccountId($domain));
     $indexer->clear();
     $indexer->index();
 }
 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);
 }
 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']);
 }