function test_raw_es() { $posts = sp_search(array('query' => array('match_all' => new stdClass()), 'fields' => array('post_id'), 'size' => 1, 'from' => 1, 'sort' => array('post_name.raw' => 'asc'))); $this->assertEquals('cat-b', $posts[0]->post_name); $s = new SP_Search(array('query' => array('match_all' => new stdClass()), 'fields' => array('post_id'), 'size' => 1, 'from' => 2, 'sort' => array('post_name.raw' => 'asc'))); $posts = $s->get_posts(); $this->assertEquals('cat-c', $posts[0]->post_name); // Test running it again $posts = $s->get_posts(); $this->assertEquals('cat-c', $posts[0]->post_name); // Verify emptiness $s = new SP_Search(array('query' => array('term' => array('post_name.raw' => array('value' => 'cucumbers'))), 'fields' => array('post_id'), 'size' => 1, 'from' => 0, 'sort' => array('post_name.raw' => 'asc'))); $this->assertEmpty($s->get_posts()); }
/** * Run a search through SearchPress using Elasticsearch syntax. * * @see SP_Search::search() * * @param array $es_args PHP array of ES arguments. * @return array Search results. */ function sp_search($es_args, $raw_result = false) { $s = new SP_Search($es_args); return $raw_result ? $s->get_results() : $s->get_posts(); }