public function SearchApiSolrTechproductsTest::testStreamingExpressions in Search API Solr 8.3
Same name and namespace in other branches
- 4.x tests/src/Kernel/SearchApiSolrTechproductsTest.php \Drupal\Tests\search_api_solr\Kernel\SearchApiSolrTechproductsTest::testStreamingExpressions()
File
- tests/
src/ Kernel/ SearchApiSolrTechproductsTest.php, line 109
Class
- SearchApiSolrTechproductsTest
- Tests the document datasources using the solr techproducts example.
Namespace
Drupal\Tests\search_api_solr\KernelCode
public function testStreamingExpressions() {
if ('false' === SOLR_CLOUD) {
$this
->markTestSkipped('This test requires a Solr Cloud setup.');
}
try {
$this
->firstSearch();
} catch (\Exception $e) {
$this
->markTestSkipped('Techproducts example not reachable.');
}
$index = $this
->getIndex();
/** @var \Drupal\search_api_solr\Utility\StreamingExpressionQueryHelper $queryHelper */
$queryHelper = \Drupal::service('search_api_solr.streaming_expression_query_helper');
$query = $queryHelper
->createQuery($index);
$exp = $queryHelper
->getStreamingExpressionBuilder($query);
$this
->assertEquals(64, $exp
->getSearchAllRows());
$search_expression = $exp
->_search_all('q="*:*"', 'fl="' . $exp
->_field('search_api_id') . '"', 'sort="' . $exp
->_field('search_api_id') . ' asc"');
$queryHelper
->setStreamingExpression($query, $search_expression);
$results = $query
->execute();
$this
->assertEquals(32, $results
->getResultCount());
$topic_expression = $exp
->_topic_all($exp
->_checkpoint('all_products'), 'q="*:*"', 'fl="' . $exp
->_field('search_api_id') . '"');
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
$this
->assertEquals(32, $results
->getResultCount());
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
$this
->assertEquals(0, $results
->getResultCount());
$topic_expression = $exp
->_topic($exp
->_checkpoint('20_products'), 'q="*:*"', 'fl="' . $exp
->_field('search_api_id') . '"', 'rows="10"');
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
// We have two shards for techproducts. Both return 10 rows.
$this
->assertEquals(20, $results
->getResultCount());
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
$this
->assertEquals(12, $results
->getResultCount());
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
$this
->assertEquals(0, $results
->getResultCount());
/** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
$backend = $index
->getServerInstance()
->getBackend();
/** @var \Drupal\search_api_solr\SolrCloudConnectorInterface $connector */
$connector = $backend
->getSolrConnector();
$connector
->deleteCheckpoints($exp
->_index_id(), $exp
->_site_hash());
$query = $queryHelper
->createQuery($index);
$queryHelper
->setStreamingExpression($query, $topic_expression);
$results = $query
->execute();
// We have two shards for techproducts. Both return 10 rows.
$this
->assertEquals(20, $results
->getResultCount());
}