function it_build_parameters_for_ingredients_and_query()
 {
     $criteria = new Criteria(0, false);
     $criteria->addQuery('blue');
     $criteria->mustContainIngredients(['vodka']);
     $this->createParameters($criteria)->shouldReturn(['index' => ElasticSearch::INDEX, 'type' => 'recipe', 'body' => ['from' => 0, 'size' => 10, 'query' => ['filtered' => ['filter' => ['and' => [['terms' => ['steps.name' => ['vodka']]]]], 'query' => ['multi_match' => ['query' => 'blue', "type" => "phrase_prefix", 'fields' => ["description.text^2", "name^4"]]]]]]]);
 }
 /**
  * @param Criteria $criteria
  */
 public function decorate(Criteria $criteria)
 {
     $alcoholFrom = $this->form->get('alcohol')->get('from')->getData();
     $alcoholTo = $this->form->get('alcohol')->get('to')->getData();
     if (!is_null($alcoholFrom)) {
         $criteria->withAlcoholContentGreaterThan($alcoholFrom);
     }
     if (!is_null($alcoholTo)) {
         $criteria->withAlcoholContentLowerThan($alcoholTo);
     }
     $criteria->addQuery($this->form->get('query')->getData());
     $criteria->mustContainIngredients($this->form->get('ingredients')->getData());
     $tasteBuilder = new TasteBuilder();
     foreach ($this->form->get('taste')->getData() as $tasteName) {
         switch ($tasteName) {
             case Tastes::SWEET:
                 $tasteBuilder->sweet();
                 break;
             case Tastes::BITTER:
                 $tasteBuilder->bitter();
                 break;
             case Tastes::SALTY:
                 $tasteBuilder->salty();
                 break;
             case Tastes::SPICY:
                 $tasteBuilder->spicy();
                 break;
             case Tastes::SOUR:
                 $tasteBuilder->sour();
                 break;
         }
     }
     $criteria->updateRequiredTaste($tasteBuilder->buildTaste());
 }
Example #3
0
 public function indexAction(Request $request)
 {
     $form = $this->get('form.factory')->createNamed('', new SearchType());
     $form->handleRequest($request);
     $criteria = new Criteria((int) $request->query->get(self::PARAM_START, 0));
     $criteria->changeSize(20);
     if ($form->isValid()) {
         $criteria->decorate(new SearchCriteriaDecorator($form));
     } else {
         if ($form->isSubmitted()) {
             $ingredients = $form->get('ingredients')->getData();
             $criteria->mustContainIngredients(is_null($ingredients) ? [] : $ingredients);
         }
     }
     $drinks = $this->get('my_drinks.search_engine')->search($criteria);
     return $this->render('search/index.html.twig', ['results' => null, 'drinks' => $drinks]);
 }