protected function SearchApiDbTest::checkFacets in Search API Database Search 7
1 call to SearchApiDbTest::checkFacets()
File
- ./
search_api_db.test, line 264
Class
- SearchApiDbTest
- Class for testing index and search capabilities using the Database search module.
Code
protected function checkFacets() {
$query = $this
->buildSearch();
$filter = $query
->createFilter('OR', array(
'facet:type',
));
$filter
->condition('type', 'article');
$query
->filter($filter);
$facets['type'] = array(
'field' => 'type',
'limit' => 0,
'min_count' => 1,
'missing' => TRUE,
'operator' => 'or',
);
$query
->setOption('search_api_facets', $facets);
$query
->range(0, 0);
$results = $query
->execute();
$this
->assertEqual($results['result count'], 2, 'OR facets query returned correct number of results.');
$expected = array(
array(
'count' => 2,
'filter' => '"article"',
),
array(
'count' => 2,
'filter' => '"item"',
),
array(
'count' => 1,
'filter' => '!',
),
);
usort($results['search_api_facets']['type'], array(
$this,
'facetCompare',
));
$this
->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned');
$query = $this
->buildSearch();
$filter = $query
->createFilter('OR', array(
'facet:type',
));
$filter
->condition('type', 'article');
$query
->filter($filter);
$filter = $query
->createFilter('AND');
$filter
->condition('type', NULL, '<>');
$query
->filter($filter);
$facets['type'] = array(
'field' => 'type',
'limit' => 0,
'min_count' => 1,
'missing' => TRUE,
'operator' => 'or',
);
$query
->setOption('search_api_facets', $facets);
$query
->range(0, 0);
$results = $query
->execute();
$this
->assertEqual($results['result count'], 2, 'OR facets query returned correct number of results.');
$expected = array(
array(
'count' => 2,
'filter' => '"article"',
),
array(
'count' => 2,
'filter' => '"item"',
),
);
usort($results['search_api_facets']['type'], array(
$this,
'facetCompare',
));
$this
->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned');
$query = $this
->buildSearch();
$filter = $query
->createFilter('OR', array(
'facet:type',
));
$filter
->condition('type', 'article');
$query
->filter($filter);
$facets['type'] = array(
'field' => 'type',
'limit' => 0,
'min_count' => 2,
'missing' => TRUE,
'operator' => 'or',
);
$query
->setOption('search_api_facets', $facets);
$query
->range(0, 0);
$results = $query
->execute();
$expected = array(
array(
'count' => 2,
'filter' => '"article"',
),
array(
'count' => 2,
'filter' => '"item"',
),
);
usort($results['search_api_facets']['type'], array(
$this,
'facetCompare',
));
$this
->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned with min_count');
$query = $this
->buildSearch();
$filter = $query
->createFilter('OR', array(
'facet:type',
));
$filter
->condition('type', 'article');
$query
->filter($filter);
$filter = $query
->createFilter('AND');
$filter
->condition('type', NULL, '<>');
$query
->filter($filter);
$facets['type'] = array(
'field' => 'type',
'limit' => 0,
'min_count' => 2,
'missing' => TRUE,
'operator' => 'or',
);
$query
->setOption('search_api_facets', $facets);
$query
->range(0, 0);
$results = $query
->execute();
$expected = array(
array(
'count' => 2,
'filter' => '"article"',
),
array(
'count' => 2,
'filter' => '"item"',
),
);
usort($results['search_api_facets']['type'], array(
$this,
'facetCompare',
));
$this
->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned with min_count');
}