You are here

protected function SearchApiDbTest::searchSuccess1 in Search API Database Search 7

1 call to SearchApiDbTest::searchSuccess1()
SearchApiDbTest::testFramework in ./search_api_db.test

File

./search_api_db.test, line 212

Class

SearchApiDbTest
Class for testing index and search capabilities using the Database search module.

Code

protected function searchSuccess1() {
  $results = $this
    ->buildSearch('test')
    ->range(1, 2)
    ->execute();
  $this
    ->assertEqual($results['result count'], 4, 'Search for »test« returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    4,
    1,
  ), 'Search for »test« returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch('test foo')
    ->execute();
  $this
    ->assertEqual($results['result count'], 3, 'Search for »test foo« returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    2,
    4,
    1,
  ), 'Search for »test foo« returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch('foo', array(
    'type,item',
  ))
    ->sort('id', 'ASC')
    ->execute();
  $this
    ->assertEqual($results['result count'], 2, 'Search for »foo« returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    1,
    2,
  ), 'Search for »foo« returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $keys = array(
    '#conjunction' => 'AND',
    'test',
    array(
      '#conjunction' => 'OR',
      'baz',
      'foobar',
    ),
    array(
      '#conjunction' => 'OR',
      '#negation' => TRUE,
      'bar',
      'fooblob',
    ),
  );
  $results = $this
    ->buildSearch($keys)
    ->execute();
  $this
    ->assertEqual($results['result count'], 1, 'Complex search 1 returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    4,
  ), 'Complex search 1 returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $query = $this
    ->buildSearch()
    ->sort('id');
  $filter = $query
    ->createFilter('OR');
  $filter
    ->condition('title', 'bar');
  $filter
    ->condition('body', 'bar');
  $query
    ->filter($filter);
  $results = $query
    ->execute();
  $this
    ->assertEqual($results['result count'], 4, 'Search with multi-field fulltext filter returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    1,
    2,
    3,
    5,
  ), 'Search with multi-field fulltext filter returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
}