You are here

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

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

File

./search_api_db.test, line 373

Class

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

Code

protected function searchSuccess2() {
  $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.');
  $query = $this
    ->buildSearch()
    ->sort('id');
  $filter = $query
    ->createFilter('OR');
  $filter
    ->condition('title', 'test');
  $filter
    ->condition('body', 'test');
  $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,
    4,
  ), '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.');
  $results = $this
    ->buildSearch(NULL, array(
    'body,test foobar',
  ))
    ->execute();
  $this
    ->assertEqual($results['result count'], 1, 'Search with multi-term fulltext filter returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    3,
  ), 'Search with multi-term fulltext filter 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'], 4, 'Search for »test foo« returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    2,
    4,
    1,
    3,
  ), 'Search for »test foo« returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(
    'foo',
  ), 'Short key was ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch('foo', array(
    'type,item',
  ))
    ->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(
    'foo',
  ), 'Short key was ignored.');
  $this
    ->assertEqual($results['warnings'], array(
    t('No valid search keys were present in the query.'),
  ), '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(
    3,
  ), 'Complex search 1 returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(
    'baz',
    'bar',
  ), 'Correct 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 2 returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    3,
  ), 'Complex search 2 returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(
    'baz',
    'bar',
  ), 'Correct keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch(NULL, array(
    'keywords,orange',
  ))
    ->execute();
  $this
    ->assertEqual($results['result count'], 3, 'Filter query 1 on multi-valued field returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    1,
    2,
    5,
  ), 'Filter query 1 on multi-valued field returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'Warning displayed.');
  $results = $this
    ->buildSearch()
    ->condition('keywords', 'orange', '<>')
    ->execute();
  $this
    ->assertEqual($results['result count'], 2, 'Negated filter on multi-valued field returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    3,
    4,
  ), 'Negated filter on multi-valued field returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'Warning displayed.');
  $filters = array(
    'keywords,orange',
    'keywords,apple',
  );
  $results = $this
    ->buildSearch(NULL, $filters)
    ->execute();
  $this
    ->assertEqual($results['result count'], 1, 'Filter query 2 on multi-valued field returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    2,
  ), 'Filter query 2 on multi-valued field returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch()
    ->condition('keywords', NULL)
    ->execute();
  $this
    ->assertEqual($results['result count'], 1, 'Query with NULL filter returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    3,
  ), 'Query with NULL filter returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  $results = $this
    ->buildSearch()
    ->condition('keywords', NULL, '<>')
    ->execute();
  $this
    ->assertEqual($results['result count'], 4, 'Query with NOT NULL filter returned correct number of results.');
  $this
    ->assertEqual(array_keys($results['results']), array(
    1,
    2,
    4,
    5,
  ), 'Query with NOT NULL filter returned correct result.');
  $this
    ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
  $this
    ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
}