Ejemplo n.º 1
0
 /**
  * @Route("/search", name="search")
  * @Method("GET")
  * @Template("AppBundle:Search:index.html.twig")
  */
 public function searchAction(Request $request)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $searchKey = strtolower($request->query->get('searchKey'));
     // $user = $this->get('security.context')->getToken()->getUser();
     $finderBucket = $this->container->get('fos_elastica.index.search.bucket');
     $finderItem = $this->container->get('fos_elastica.index.search.item');
     $boolQuery1 = new \Elastica\Query\BoolQuery();
     $terms1 = new \Elastica\Query\Terms();
     $terms1->setTerms('name', array($searchKey));
     $boolQuery1->addMust($terms1);
     $queryId1 = new \Elastica\Query\Terms();
     $queryId1->setTerms('id', [$user->getId()]);
     $nestedQuery1 = new \Elastica\Query\Nested();
     $nestedQuery1->setPath('user');
     $nestedQuery1->setQuery($queryId1);
     $boolQuery1->addMust($nestedQuery1);
     $buckets = $finderBucket->search($boolQuery1);
     $boolQuery2 = new \Elastica\Query\BoolQuery();
     $termsTitle = new \Elastica\Query\Terms();
     $termsContent = new \Elastica\Query\Terms();
     $termsTitle->setTerms('title', array($searchKey));
     $boolQuery2->addMust($termsTitle);
     $termsContent->setTerms('content', array($searchKey));
     $boolQuery2->addShould($termsContent);
     $queryId2 = new \Elastica\Query\Terms();
     $queryId2->setTerms('id', [$user->getId()]);
     $nestedQuery2 = new \Elastica\Query\Nested();
     $nestedQuery2->setPath('user');
     $nestedQuery2->setQuery($queryId2);
     $boolQuery2->addMust($nestedQuery2);
     $items = $finderItem->search($boolQuery2);
     return ['searchKey' => $searchKey, 'buckets' => $buckets, 'items' => $items, 'allBuckets' => $this->getAllBuckets($user)];
 }
Ejemplo n.º 2
0
 public function getArticles($user, $searchTerm, $page, $pageOffset, $category, $colors, $finder)
 {
     $boolQuery = new \Elastica\Query\BoolQuery();
     if ($category != NULL) {
         $categoryQuery = new \Elastica\Query\Terms();
         $categoryQuery->setTerms('custdata.customCatRef', array($category));
         $boolQuery->addMust($categoryQuery);
     }
     if ($searchTerm) {
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('customerRef', $user->getCustomerRef());
         $boolQuery->addMust($fieldQuery);
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('allField', $searchTerm);
         $fieldQuery->setFieldOperator('allField', 'AND');
         $fieldQuery->setFieldMinimumShouldMatch('allField', '70%');
         $fieldQuery->setFieldFuzziness('allField', '0.8');
         $fieldQuery->setFieldAnalyzer('allField', 'custom_search_analyzer');
         $boolQuery->addMust($fieldQuery);
     } else {
         $fieldQuery = new \Elastica\Query\MatchAll();
         $boolQuery->addMust($fieldQuery);
     }
     $fieldQuery = new \Elastica\Query\Nested();
     $fieldQuery->setPath('custdata.custcat.perm');
     $boolNested = new \Elastica\Query\BoolQuery();
     $fieldNested = new \Elastica\Query\Match();
     $fieldNested->setField('custdata.custcat.perm.permStatus', 1);
     $boolNested->addMust($fieldNested);
     $fieldNested = new \Elastica\Query\Match();
     $fieldNested->setField('custdata.custcat.perm.userRef', $user->getId());
     $boolNested->addMust($fieldNested);
     $fieldQuery->setQuery($boolNested);
     $boolQuery->addMust($fieldQuery);
     if ($colors != NULL) {
         $colorQuery = new \Elastica\Query\Terms();
         $colorQuery->setTerms('variants.variantvalues.otherTerms', $colors);
         $colorNested = new \Elastica\Query\Nested('variants');
         $colorNested->setPath('variants.variantvalues');
         $colorNested->setQuery($colorQuery);
         $boolQuery->addMust($colorNested);
     }
     $query = new \Elastica\Query();
     $query->setQuery($boolQuery);
     $query->setSize(12);
     $query->setFrom($pageOffset);
     $articles = $finder->find($query);
     $result = array("articles" => $articles, "rQuery" => $query);
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @Route("/app/search", name="search")
  * @Template("AppBundle::search.html.twig")
  */
 public function searchAction(Request $request)
 {
     $q = $request->query->get('q');
     $finder = $this->get('fos_elastica.finder.app');
     $tenantHelper = $this->get('multi_tenant.helper');
     $boolQuery = new \Elastica\Query\BoolQuery();
     $fieldQuery = new \Elastica\Query\MultiMatch();
     $fieldQuery->setQuery($q);
     $fieldQuery->setFields(['_all']);
     $boolQuery->addMust($fieldQuery);
     $tenantQuery = new \Elastica\Query\Term();
     $tenantQuery->setTerm('id', $tenantHelper->getCurrentTenant()->getId());
     $nestedQuery = new \Elastica\Query\Nested();
     $nestedQuery->setPath('tenant');
     $nestedQuery->setQuery($tenantQuery);
     $boolQuery->addMust($nestedQuery);
     $results = $finder->findPaginated($boolQuery);
     return ['results' => $results, 'query' => $q];
 }
Ejemplo n.º 4
0
 public function getBestImg($searchTerm, $articleRef, $colors, $finder)
 {
     $boolQuery = new \Elastica\Query\BoolQuery();
     if ($searchTerm) {
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('desc1', $searchTerm);
         $fieldQuery->setFieldOperator('desc1', 'OR');
         $fieldQuery->setFieldMinimumShouldMatch('desc1', '80%');
         $fieldQuery->setFieldAnalyzer('desc1', 'custom_search_analyzer');
         $boolQuery->addShould($fieldQuery);
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('desc2', $searchTerm);
         $fieldQuery->setFieldOperator('desc2', 'OR');
         $fieldQuery->setFieldMinimumShouldMatch('desc2', '80%');
         $fieldQuery->setFieldAnalyzer('desc2', 'custom_search_analyzer');
         $varTerms = explode(" ", $searchTerm);
         $boolQuery->addShould($fieldQuery);
         $colorQuery = new \Elastica\Query\Terms();
         $colorQuery->setTerms('variantvalues.otherTerms', $varTerms);
         $colorNested = new \Elastica\Query\Nested('variantvalues');
         $colorNested->setPath('variantvalues');
         $colorNested->setQuery($colorQuery);
         $boolQuery->addShould($colorNested);
         if ($colors != NULL) {
             $fieldQuery = new \Elastica\Query\Terms();
             $fieldQuery->setTerms('otherTerms', $colors);
             $boolQuery->addShould($fieldQuery);
         }
     }
     $articleRefQuery = new \Elastica\Query\Terms();
     $articleRefQuery->setTerms('articleRef', array($articleRef));
     $boolQuery->addMust($articleRefQuery);
     if ($colors != NULL) {
         $colorQuery = new \Elastica\Query\Terms();
         $colorQuery->setTerms('variantvalues.otherTerms', $colors);
         $colorNested = new \Elastica\Query\Nested('variantvalues');
         $colorNested->setPath('variantvalues');
         $colorNested->setQuery($colorQuery);
         $boolQuery->addMust($colorNested);
     }
     $query = new \Elastica\Query();
     $query->setQuery($boolQuery);
     $query->setSize(12);
     $articleVar = $finder->find($query);
     return $articleVar;
 }