コード例 #1
0
 /**
  *
  * @Route("", name="centrale_lille_searchuser")
  * @Method("GET")
  */
 public function searchAction(Request $request)
 {
     $search = new SearchString();
     $searchForm = $this->get('form.factory')->createNamed('', 'string_search_type', $search, array('action' => $this->generateUrl('centrale_lille_searchuser'), 'method' => 'GET'));
     $searchForm->handleRequest($request);
     $search = $searchForm->getData();
     if (is_null($search->getStringSearch())) {
         $result_machine = [];
         $result_user = [];
     } else {
         //Recherche User
         $typeUser = $this->get('fos_elastica.index.fablab.User');
         $query_part_user = new \Elastica\Query\BoolQuery();
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery2 = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('email', $search->getStringSearch());
         $fieldQuery->setFieldQuery('email', $search->getStringSearch());
         $fieldQuery->setFieldFuzziness('email', 0.7);
         $query_part_user->addShould($fieldQuery);
         $fieldQuery2->setFieldQuery('username', $search->getStringSearch());
         $fieldQuery2->setFieldQuery('username', $search->getStringSearch());
         $fieldQuery2->setFieldFuzziness('username', 0.7);
         $query_part_user->addShould($fieldQuery2);
         $filters = new \Elastica\Filter\Bool();
         $query_user = new \Elastica\Query\Filtered($query_part_user, $filters);
         $result_user = $typeUser->search($query_user);
         //Recherche Machine
         $typeMachine = $this->get('fos_elastica.index.fablab.Machine');
         $query_part_machine = new \Elastica\Query\Bool();
         $fieldQuery3 = new \Elastica\Query\Match();
         $fieldQuery4 = new \Elastica\Query\Match();
         $fieldQuery3->setFieldQuery('machine_name', $search->getStringSearch());
         $fieldQuery3->setFieldFuzziness('machine_name', 0.7);
         $fieldQuery3->setFieldMinimumShouldMatch('machine_name', '80%');
         $query_part_machine->addShould($fieldQuery3);
         $fieldQuery4->setFieldQuery('description', $search->getStringSearch());
         $fieldQuery4->setFieldFuzziness('description', 2);
         $fieldQuery4->setFieldMinimumShouldMatch('description', '100%');
         $query_part_machine->addShould($fieldQuery4);
         $filters = new \Elastica\Filter\Bool();
         $query_machine = new \Elastica\Query\Filtered($query_part_machine, $filters);
         $result_machine = $typeMachine->search($query_machine);
         //Recherche Machine
         $typeMachine = $this->get('fos_elastica.index.fablab.Machine');
         $query_part_machine = new \Elastica\Query\Bool();
         $fieldQuery3 = new \Elastica\Query\Match();
         $fieldQuery4 = new \Elastica\Query\Match();
         $fieldQuery3->setFieldQuery('machine_name', $search->getStringSearch());
         // $fieldQuery3->setFieldFuzziness('machine.machine_name', 0.7);
         //$fieldQuery3->setFieldMinimumShouldMatch('machine_name', '80%');
         $query_part_machine->addShould($fieldQuery3);
         $fieldQuery4->setFieldQuery('description', $search->getStringSearch());
         // $fieldQuery4->setFieldFuzziness('machine.machine_name', 0.7);
         //$fieldQuery4->setFieldMinimumShouldMatch('machine_name', '100%');
         $query_part_machine->addShould($fieldQuery4);
     }
     return $this->render('CentraleLilleSearchBundle:Default:search.html.twig', array('result_user' => $result_user, 'result_machine' => $result_machine, 'form' => $searchForm->createView(), 'search' => $search->getStringSearch()));
 }
コード例 #2
0
 public function searchKey($key)
 {
     if ($key) {
         $bool = new \Elastica\Query\BoolQuery();
         $bool->addShould(new \Elastica\Query\Match('boitier.libelleBoitier', $key));
         $bool->addShould(new \Elastica\Query\Match('carburant.libelleCarburant', $key));
         $bool->addShould(new \Elastica\Query\Match('modeleMarque.modele.libelleModele', $key));
         $bool->addShould(new \Elastica\Query\Match('modeleMarque.marque.libelleMarque', $key));
         $query = \Elastica\Query::create($bool);
     } else {
         $match = new \Elastica\Query\MatchAll();
         $query = \Elastica\Query::create($match);
     }
     return $this->find($query);
 }
コード例 #3
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)];
 }
コード例 #4
0
 /**
  *
  * @Route("", name="centrale_lille_search")
  */
 public function searchAction()
 {
     $jsonContentUser = '';
     $jsonContentMachine = '';
     $jsonContentProjet = '';
     $jsonContentSkills = '';
     $jsonTotal = '';
     $datauser = [];
     $dataprojet = [];
     $dataskills = [];
     $datamachine = [];
     $search = $this->get('request')->query->get('searchForm');
     if (is_null($search)) {
         $result_machine = [];
         $result_user = [];
         $result_skills = [];
         $result_projet = [];
     } else {
         //User Json
         $queryall = new \Elastica\Query\MatchAll();
         $typeUser = $this->get('fos_elastica.index.fablab.User');
         $result_alluser = $typeUser->search($queryall)->getResults();
         foreach ($result_alluser as $result) {
             $source = $result->getSource();
             $datauser[] = array('name' => $source['username'], 'link' => 'userId');
         }
         $jsonContentUser = new JsonResponse($datauser, 200, array('Cache-Control' => 'no-cache'));
         //Project Json
         $queryall = new \Elastica\Query\MatchAll();
         $typeProjet = $this->get('fos_elastica.index.fablab.Projet');
         $result_allprojet = $typeProjet->search($queryall)->getResults();
         foreach ($result_allprojet as $result) {
             $source = $result->getSource();
             $dataprojet[] = array('name' => $source['name'], 'link' => 'projectId');
         }
         $jsonContentProjet = new JsonResponse($dataprojet, 200, array('Cache-Control' => 'no-cache'));
         //Skills Json
         $queryall = new \Elastica\Query\MatchAll();
         $typeSkills = $this->get('fos_elastica.index.fablab.Competence');
         $result_allskills = $typeSkills->search($queryall)->getResults();
         foreach ($result_allskills as $result) {
             $source = $result->getSource();
             $dataskills[] = array('name' => $source['name'], 'link' => 'skillsId');
         }
         $jsonContentSkills = new JsonResponse($dataskills, 200, array('Cache-Control' => 'no-cache'));
         //Machine Json
         $queryall = new \Elastica\Query\MatchAll();
         $typeMachine = $this->get('fos_elastica.index.fablab.Machine');
         $result_allmachine = $typeMachine->search($queryall)->getResults();
         foreach ($result_allmachine as $result) {
             $source = $result->getSource();
             $type = $result->getType();
             $datamachine[] = array('name' => $source['name'], 'link' => 'machineId');
         }
         $jsonContentMachine = new JsonResponse($datamachine, 200, array('Cache-Control' => 'no-cache'));
         $jsonContentMachine = '"machine": ' . substr($jsonContentMachine, 83);
         $jsonContentUser = '******' . substr($jsonContentUser, 83);
         $jsonContentSkills = '"competence": ' . substr($jsonContentSkills, 83);
         $jsonContentProjet = '"projet": ' . substr($jsonContentProjet, 83);
         $jsonTotal = '{' . $jsonContentUser . ',' . $jsonContentMachine . ',' . $jsonContentProjet . ',' . $jsonContentSkills . '}';
         //Recherche User
         $typeUser = $this->get('fos_elastica.index.fablab.User');
         $query_part_user = new \Elastica\Query\BoolQuery();
         $fieldQuery = new \Elastica\Query\Match();
         $fieldQuery2 = new \Elastica\Query\Match();
         $fieldQuery9 = new \Elastica\Query\Match();
         $fieldQuery10 = new \Elastica\Query\Match();
         $fieldQuery->setFieldQuery('email', $search);
         $fieldQuery->setFieldFuzziness('email', 0.2);
         $query_part_user->addShould($fieldQuery);
         $fieldQuery9->setFieldQuery('firstname', $search);
         $fieldQuery9->setFieldFuzziness('firstname', 0.2);
         $query_part_user->addShould($fieldQuery9);
         $fieldQuery10->setFieldQuery('lastname', $search);
         $fieldQuery10->setFieldFuzziness('lastname', 0.2);
         $query_part_user->addShould($fieldQuery10);
         $fieldQuery2->setFieldQuery('username', $search);
         $fieldQuery2->setFieldFuzziness('username', 0.2);
         $query_part_user->addShould($fieldQuery2);
         $filters = new \Elastica\Filter\Bool();
         $query_user = new \Elastica\Query\Filtered($query_part_user, $filters);
         $result_user = $typeUser->search($query_user);
         //Recherche Machine
         $typeMachine = $this->get('fos_elastica.index.fablab.Machine');
         $query_part_machine = new \Elastica\Query\Bool();
         $fieldQuery3 = new \Elastica\Query\Match();
         $fieldQuery4 = new \Elastica\Query\Match();
         $fieldQuery3->setFieldQuery('name', $search);
         $fieldQuery3->setFieldFuzziness('name', 0.2);
         $fieldQuery3->setFieldMinimumShouldMatch('name', '80%');
         $query_part_machine->addShould($fieldQuery3);
         $fieldQuery4->setFieldQuery('description', $search);
         $fieldQuery4->setFieldFuzziness('description', 2);
         $fieldQuery4->setFieldMinimumShouldMatch('description', '100%');
         $query_part_machine->addShould($fieldQuery4);
         $filters = new \Elastica\Filter\Bool();
         $query_machine = new \Elastica\Query\Filtered($query_part_machine, $filters);
         $result_machine = $typeMachine->search($query_machine);
         //Recherche Skills
         $typeSkills = $this->get('fos_elastica.index.fablab.Competence');
         $query_part_skills = new \Elastica\Query\Bool();
         $fieldQuery5 = new \Elastica\Query\Match();
         $fieldQuery5->setFieldQuery('name', $search);
         $fieldQuery5->setFieldFuzziness('name', 2);
         $fieldQuery5->setFieldMinimumShouldMatch('name', '40%');
         $query_part_skills->addShould($fieldQuery5);
         $filters = new \Elastica\Filter\Bool();
         $query_skills = new \Elastica\Query\Filtered($query_part_skills, $filters);
         $result_skills = $typeSkills->search($query_skills);
         //Recherche projet
         $typeProjet = $this->get('fos_elastica.index.fablab.Projet');
         $query_part_projet = new \Elastica\Query\Bool();
         $fieldQuery6 = new \Elastica\Query\Match();
         $fieldQuery7 = new \Elastica\Query\Match();
         $fieldQuery6->setFieldQuery('name', $search);
         $fieldQuery6->setFieldFuzziness('name', 0.2);
         $fieldQuery6->setFieldMinimumShouldMatch('name', '80%');
         $query_part_projet->addShould($fieldQuery6);
         $fieldQuery7->setFieldQuery('summary', $search);
         $fieldQuery7->setFieldFuzziness('summary', 2);
         $fieldQuery7->setFieldMinimumShouldMatch('summary', '100%');
         $query_part_projet->addShould($fieldQuery7);
         $filters = new \Elastica\Filter\Bool();
         $query_projet = new \Elastica\Query\Filtered($query_part_projet, $filters);
         $result_projet = $typeProjet->search($query_projet);
         //
         $encoder = array(new JsonEncoder());
         $normalizer = array(new ObjectNormalizer());
         $serializer = new Serializer($normalizer, $encoder);
     }
     return $this->render('CentraleLilleSearchBundle:Default:search.html.twig', array('result_user' => $result_user, 'result_machine' => $result_machine, 'result_competence' => $result_skills, 'result_project' => $result_projet, 'search' => $search, 'userjson' => $jsonContentUser, 'machinejson' => $jsonContentMachine, 'jsonTotal' => $jsonTotal));
 }
コード例 #5
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;
 }
コード例 #6
0
 /**
  * Apply PageType specific and Page specific boosts
  *
  * @return \Elastica\Query\BoolQuery
  */
 protected function getPageBoosts()
 {
     $rescoreQueryBool = new \Elastica\Query\BoolQuery();
     //Apply page type boosts
     $pageClasses = $this->em->getRepository('KunstmaanNodeBundle:Node')->findAllDistinctPageClasses();
     foreach ($pageClasses as $pageClass) {
         $page = new $pageClass['refEntityName']();
         if ($page instanceof SearchBoostInterface) {
             $elasticaQueryTypeBoost = new \Elastica\Query\QueryString();
             $elasticaQueryTypeBoost->setBoost($page->getSearchBoost())->setDefaultField('page_class')->setQuery(addslashes($pageClass['refEntityName']));
             $rescoreQueryBool->addShould($elasticaQueryTypeBoost);
         }
     }
     //Apply page specific boosts
     $nodeSearches = $this->em->getRepository('KunstmaanNodeSearchBundle:NodeSearch')->findAll();
     foreach ($nodeSearches as $nodeSearch) {
         $elasticaQueryNodeId = new \Elastica\Query\QueryString();
         $elasticaQueryNodeId->setBoost($nodeSearch->getBoost())->setDefaultField('node_id')->setQuery($nodeSearch->getNode()->getId());
         $rescoreQueryBool->addShould($elasticaQueryNodeId);
     }
     return $rescoreQueryBool;
 }