Пример #1
0
 function test_histograms()
 {
     $s = new SP_WP_Search(array('post_type' => array('post', 'page'), 'posts_per_page' => 0, 'facets' => array('Year' => array('type' => 'date_histogram', 'interval' => 'year', 'count' => 10), 'Month' => array('type' => 'date_histogram', 'interval' => 'month', 'count' => 10), 'Day' => array('type' => 'date_histogram', 'interval' => 'day', 'field' => 'post_modified', 'count' => 10))));
     $facet_data = $s->get_facet_data();
     $this->assertEquals('2007', $facet_data['Year']['items'][0]['name']);
     $this->assertEquals('2008', $facet_data['Year']['items'][1]['name']);
     $this->assertEquals('2009', $facet_data['Year']['items'][2]['name']);
     $this->assertEquals('2010', $facet_data['Year']['items'][3]['name']);
     $this->assertEquals(7, $facet_data['Year']['items'][0]['count']);
     $this->assertEquals(1, $facet_data['Year']['items'][1]['count']);
     $this->assertEquals(13, $facet_data['Year']['items'][2]['count']);
     $this->assertEquals(13, $facet_data['Year']['items'][3]['count']);
     $this->assertEquals(array('year' => '2007'), $facet_data['Year']['items'][0]['query_vars']);
     $this->assertEquals(array('year' => '2008'), $facet_data['Year']['items'][1]['query_vars']);
     $this->assertEquals(array('year' => '2009'), $facet_data['Year']['items'][2]['query_vars']);
     $this->assertEquals(array('year' => '2010'), $facet_data['Year']['items'][3]['query_vars']);
     $this->assertEquals('January 2007', $facet_data['Month']['items'][0]['name']);
     $this->assertEquals(7, $facet_data['Month']['items'][0]['count']);
     $this->assertEquals(array('year' => '2007', 'monthnum' => 1), $facet_data['Month']['items'][0]['query_vars']);
     $this->assertEquals('January 1, 2007', $facet_data['Day']['items'][0]['name']);
     $this->assertEquals(7, $facet_data['Day']['items'][0]['count']);
     $this->assertEquals(array('year' => '2007', 'monthnum' => 1, 'day' => 1), $facet_data['Day']['items'][0]['query_vars']);
 }
Пример #2
0
 function test_invalid_sorting()
 {
     $es_args = SP_WP_Search::wp_to_es_args(array('orderby' => 'modified', 'order' => 'desc'));
     $this->assertEquals('desc', $es_args['sort'][0]['post_modified.date'], 'Verify es_args["sort"] exists');
     $es_args = SP_WP_Search::wp_to_es_args(array('orderby' => 'modified_gmt'));
     $this->assertTrue(empty($es_args['sort']), 'Verify es_args["sort"] exists');
 }
Пример #3
0
/**
 * Run a search through SearchPress using WP-friendly syntax.
 *
 * @see SP_WP_Search
 *
 * @param  array $wp_args PHP array of search arguments.
 * @return array Search results.
 */
function sp_wp_search($wp_args, $raw_result = false)
{
    $s = new SP_WP_Search($wp_args);
    return $raw_result ? $s->get_results() : $s->get_posts();
}