public function testIfWillFilterByAndStatusAndSearch() { $nums = $this->makeData(); $criteria = new SearchCriteria(); $criteria->addCond('status', '==', m::StatusInactive); $criteria->search('Vienna'); $dp = new SearchProvider(m::class); $dp->setCriteria($criteria); $this->assertSame(2, $dp->getItemCount(), 'That current result set has items'); }
public function testIfWillFindDocumentsAndSetItsIndexName() { $model = $this->prepare(); $criteria = new SearchCriteria(); $criteria->search('shanghai'); $dp = new SearchProvider($model); $dp->setCriteria($criteria); $results = $dp->getData(); $this->assertGreaterThan(0, count($results), 'That something was found'); foreach ($results as $result) { /* @var $result ModelWithIndex */ $index = $result->getIndex(); codecept_debug($index); $this->assertInternalType('string', $index, 'That found result has set index'); } }
public function testIfWillFindDocumentsAndSetItsScore() { $model = $this->prepare(); $criteria = new SearchCriteria(); $criteria->search('shanghai'); $dp = new SearchProvider($model); $dp->setCriteria($criteria); $results = $dp->getData(); $this->assertGreaterThan(0, count($results), 'That something was found'); foreach ($results as $result) { /* @var $result ModelWithScore */ $score = $result->getScore(); codecept_debug($score); $this->assertGreaterThan(0, $score, 'That found result has some score'); } }
public function testIfWillFindProperlyCountWithSearchProviderPagination() { $model = $this->prepare(); $criteria = new SearchCriteria(); $criteria->search('shanghai'); $pagination = new Pagination(); $pagination->setSize(2); $dp = new SearchProvider($model); $dp->setPagination($pagination); $dp->setCriteria($criteria); $this->assertSame(7, $dp->getTotalItemCount(), 'That total is 7 items'); $this->assertSame(2, $dp->getItemCount(), 'That current result set has 2 items'); $results = $dp->getData(); $this->assertSame(2, count($results), 'That 2 result was returned'); $this->assertTrue(array_key_exists(0, $results), 'That results starts with key 0'); foreach ($results as $i => $result) { $this->assertInstanceOf(SimpleModel::class, $result, "That result {$i} has proper type"); $this->assertSame('Shanghai', $result->title, "That title is properly populated"); } }
private function getParams($q = null) { $body = []; // Try to get query from criteria if empty $criteria = $this->getCriteria(); if (empty($criteria)) { $criteria = new SearchCriteria(); } if (!empty($q)) { $criteria->search($q); } $decorator = new QueryBuilderDecorator($this->manganel); $decorator->decorate($body, $criteria); if (empty($this->models)) { $type = '_all'; } else { $types = []; foreach ($this->models as $model) { if (!$model instanceof AnnotatedInterface) { throw new UnexpectedValueException(sprintf('Expected `%s` instance, got `%s`', AnnotatedInterface::class, is_object($model) ? get_class($model) : gettype($model))); } $types[] = CollectionNamer::nameCollection($model); } $type = implode(',', array_unique($types)); } $params = ['index' => strtolower($this->manganel->index), 'type' => $type, 'body' => $body]; return $params; }