Example #1
0
 public function decorate(&$body, SearchCriteria $criteria)
 {
     if ($criteria->getLimit() || $criteria->getOffset()) {
         $body['from'] = $criteria->getOffset();
         $body['size'] = $criteria->getLimit();
     }
 }
Example #2
0
 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');
 }
Example #3
0
 public function decorate(&$conditions, SearchCriteria $criteria)
 {
     $q = $criteria->getSearch();
     if (empty($q)) {
         // Match all documents if query is null
         $conditions[] = ['match_all' => []];
     } else {
         // Use query string matching
         $conditions[] = ['simple_query_string' => ['query' => $q]];
     }
 }
 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");
     }
 }
Example #7
0
 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;
 }
 public function decorate(&$conditions, SearchCriteria $criteria)
 {
     foreach ($criteria->getConditions() as $name => $value) {
         $conditions[] = ['term' => [$name => $value]];
     }
 }