public function newsAction(Request $request) { $request = $this->getRequest(); $pageOffset = 0; if ($request->query->get('p')) { $page = $request->query->get('p'); $pageOffset = ($page - 1) * 6; } $finder = $this->container->get('fos_elastica.finder.search.posts'); $boolQuery = new \Elastica\Query\BoolQuery(); if ($request->query->get('q')) { $search = $request->query->get('q'); $fieldQuery = new \Elastica\Query\Match(); $fieldQuery->setFieldQuery('allField', $search); $fieldQuery->setFieldOperator('allField', 'AND'); $fieldQuery->setFieldMinimumShouldMatch('allField', '80%'); $fieldQuery->setFieldAnalyzer('allField', 'custom_search_analyzer'); $boolQuery->addMust($fieldQuery); } else { $fieldQuery = new \Elastica\Query\MatchAll(); } $query = new \Elastica\Query(); $query->setQuery($boolQuery); $query->setSize(1000); $totalpages = ceil(count($finder->find($query)) / 6); $query->setSize(6); $query->setFrom($pageOffset); $posts = $finder->find($query); return $this->render('TeamIndexBundle:News:news.html.twig', array('posts' => $posts, 'totalpages' => $totalpages)); }
public function getQueryForSearch(ArticleSearch $articleSearch) { // we create a query to return all the articles // but if the criteria title is specified, we use it if ($articleSearch->getTitle() !== null && $articleSearch != '') { $query = new \Elastica\Query\Match(); $query->setFieldQuery('article.title', $articleSearch->getTitle()); $query->setFieldFuzziness('article.title', 0.7); $query->setFieldMinimumShouldMatch('article.title', '80%'); } else { $query = new \Elastica\Query\MatchAll(); } // then we create filters depending on the chosen criterias $boolQuery = new \Elastica\Query\Bool(); $boolQuery->addMust($query); /* Dates filter We add this filter only the ispublished filter is not at "false" */ if ("false" != $articleSearch->isPublished() && null !== $articleSearch->getDateFrom() && null !== $articleSearch->getDateTo()) { $boolQuery->addMust(new \Elastica\Query\Range('publishedAt', array('gte' => \Elastica\Util::convertDate($articleSearch->getDateFrom()->getTimestamp()), 'lte' => \Elastica\Util::convertDate($articleSearch->getDateTo()->getTimestamp())))); } // Published or not filter if ($articleSearch->isPublished() !== null) { $boolQuery->addMust(new \Elastica\Query\Terms('published', array($articleSearch->isPublished()))); } $query = new \Elastica\Query($boolQuery); $query->setSort(array($articleSearch->getSort() => array('order' => $articleSearch->getDirection()))); return $query; }
/** * @param mixed $query * @param string $type * * @return mixed|void */ public function defineSearch($query, $type) { $query = \Elastica\Util::escapeTerm($query); $elasticaQueryString = new \Elastica\Query\Match(); $elasticaQueryString->setFieldMinimumShouldMatch('content', '80%')->setFieldQuery('content', $query); if ($this->useMatchQueryForTitle) { $elasticaQueryTitle = new \Elastica\Query\Match(); $elasticaQueryTitle->setFieldQuery('title', $query)->setFieldMinimumShouldMatch('title', '80%'); } else { $elasticaQueryTitle = new \Elastica\Query\QueryString(); $elasticaQueryTitle->setDefaultField('title')->setQuery($query); } $elasticaQueryBool = new \Elastica\Query\BoolQuery(); $elasticaQueryBool->addShould($elasticaQueryTitle)->addShould($elasticaQueryString)->setMinimumNumberShouldMatch(1); $this->applySecurityFilter($elasticaQueryBool); if (!is_null($type)) { $elasticaQueryType = new \Elastica\Query\Term(); $elasticaQueryType->setTerm('type', $type); $elasticaQueryBool->addMust($elasticaQueryType); } $rootNode = $this->domainConfiguration->getRootNode(); if (!is_null($rootNode)) { $elasticaQueryRoot = new \Elastica\Query\Term(); $elasticaQueryRoot->setTerm('root_id', $rootNode->getId()); $elasticaQueryBool->addMust($elasticaQueryRoot); } $rescore = new \Elastica\Rescore\Query(); $rescore->setRescoreQuery($this->getPageBoosts()); $this->query->setQuery($elasticaQueryBool); $this->query->setRescore($rescore); $this->query->setHighlight(array('pre_tags' => array('<strong>'), 'post_tags' => array('</strong>'), 'fields' => array('content' => array('fragment_size' => 150, 'number_of_fragments' => 3)))); }
public function articlelistAction(Request $request) { $em = $this->getDoctrine()->getManager(); $searchTerm = $request->query->get('q'); $page = 0; $pageOffset = 0; if ($request->query->get('p')) { $page = $request->query->get('p'); $pageOffset = ($page - 1) * 12; } $finder = $this->container->get('fos_elastica.finder.search.article'); $boolQuery = new \Elastica\Query\BoolQuery(); $articles = ""; $totalpages = 0; if ($request->query->get('q') != NULL) { $searchTerm = $request->query->get('q'); $fieldQuery = new \Elastica\Query\Match(); $fieldQuery->setFieldQuery('allField', $searchTerm); $fieldQuery->setFieldOperator('allField', 'AND'); $fieldQuery->setFieldMinimumShouldMatch('allField', '80%'); $fieldQuery->setFieldAnalyzer('allField', 'custom_search_analyzer'); $boolQuery->addMust($fieldQuery); $query = new \Elastica\Query(); $query->setQuery($boolQuery); $query->setSize(10000); $articleCatgeories = $finder->find($query); $totalpages = ceil(count($finder->find($query)) / 12); $query->setSize(12); $query->setFrom($pageOffset); $articles = $finder->find($query); } return $this->render('OrthAdminBundle:Articles:articlelist.html.twig', array('totalpages' => $totalpages, 'articles' => $articles)); }
/** * * @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())); }
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; }
public function searchAdvanced($q = '') { if ($q == '') { $baseQuery = new \Elastica\Query\MatchAll(); } else { $baseQuery = new \Elastica\Query\Match(); $baseQuery->setFieldQuery('description', $q); $baseQuery->setFieldFuzziness('description', 0.7); $baseQuery->setFieldMinimumShouldMatch('description', '80%'); } $boolFilter = new \Elastica\Filter\BoolFilter(); $dateFrom = new \DateTime(); $dateFrom->sub(new \DateInterval('P7D')); $dateTo = new \DateTime(); $dateTo->add(new \DateInterval('P1D')); $boolFilter->addMust(new \Elastica\Filter\Range('createdAt', array('gte' => \Elastica\Util::convertDate($dateFrom->getTimestamp()), 'lte' => \Elastica\Util::convertDate($dateTo->getTimestamp())))); /* * $boolFilter->addMust( * new \Elastica\Filter\Term(array('isPublished' => true)) * ); * $boolFilter->addMust( * new \Elastica\Filter\Terms('isPublished', array('1', '2', '3')) * ); */ /* * $baseQuery = new \Elastica\Filter\Bool(); * $baseQuery->addShould( * new \Elastica\Filter\Term(array('id' => intval($q))) * ); * $baseQuery->addShould( * new \Elastica\Filter\Term(array('amount' => floatval($q))) * ); * $filtered = new \Elastica\Query\Filtered(); * $filtered->setFilter($baseQuery); * return $this->finder->find($filtered); */ /* * $baseQuery = new \Elastica\Query\Bool; * $idQueryTerm = new \Elastica\Query\Term; * $idQueryTerm->setTerm('id', intval($q)); * $baseQuery->addShould($idQueryTerm); */ $filtered = new \Elastica\Query\Filtered($baseQuery, $boolFilter); $query = \Elastica\Query::create($filtered); $query->addSort(array('id' => array('order' => 'asc'))); $query->setSize(1); return $this->find($query); }
/** * * @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)); }
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; }
public function searchAction(Request $request) { $em = $this->getDoctrine()->getManager(); $username = $request->query->get('oci_username'); $password = $request->query->get('oci_password'); $hookurl = $request->query->get('hookurl'); $response = new Response(); $response->headers->clearCookie('OCIHOOK'); $response->headers->clearCookie('OrthCookie'); $response->sendHeaders(); $response->send(); $response->headers->setCookie(new Cookie('OCIHOOK', $hookurl)); $cookieValue = uniqid(); $response->headers->setCookie(new Cookie('OrthCookie', uniqid())); $response->sendHeaders(); $response->send(); $query = $em->createQuery("SELECT u FROM Orth\\IndexBundle\\Entity\\Users u WHERE u.email = :username"); $query->setParameter('username', $username); $user = $query->getOneOrNullResult(); if ($user) { // Get the encoder for the users password $encoder_service = $this->get('security.encoder_factory'); $encoder = $encoder_service->getEncoder($user); // Note the difference if ($encoder->isPasswordValid($user->getPassword(), $password, '$2a$12$uWepESKverBsrLAuOPY')) { // Get profile list } else { dump('fail1'); exit; } } else { dump('fail'); exit; } $token = new UsernamePasswordToken($user, null, "default", $user->getRoles()); $this->get("security.context")->setToken($token); //now the user is logged in //now dispatch the login event $request = $this->get("request"); $event = new InteractiveLoginEvent($request, $token); $this->get("event_dispatcher")->dispatch("security.interactive_login", $event); if ($request->query->get('FUNCTION') == NULL) { return $this->redirectToRoute('orth_index_homepage', array(), 301); } $searchTerm = $request->query->get('SEARCHSTRING'); $page = 0; $pageOffset = 0; $catId = $request->query->get('cid'); $finder = $this->container->get('fos_elastica.finder.search.article'); $boolQuery = new \Elastica\Query\BoolQuery(); if ($request->query->get('c') != NULL and $request->query->get('SEARCHSTRING') == NULL) { $catid = $request->query->get('c'); $categoryArray = [$request->query->get('c')]; $rootCategories = $em->getRepository('OrthIndexBundle:Categories')->findBy(array('parentId' => $catid)); foreach ($rootCategories as $childCategory) { $childCategories = $em->getRepository('OrthIndexBundle:Categories')->findBy(array('parentId' => $childCategory->getId())); $categoryArray[] = $childCategory->getId(); foreach ($childCategories as $grandchildCategory) { $categoryArray[] = $grandchildCategory->getId(); } } $categoryQuery = new \Elastica\Query\Terms(); $categoryQuery->setTerms('catRef', $categoryArray); $boolQuery->addMust($categoryQuery); } elseif ($request->query->get('c') != NULL) { $catid = $request->query->get('c'); $categoryQuery = new \Elastica\Query\Terms(); $categoryQuery->setTerms('catRef', array($catid)); $boolQuery->addMust($categoryQuery); } if ($request->query->get('SEARCHSTRING')) { $fieldQuery = new \Elastica\Query\Match(); $fieldQuery->setFieldQuery('allField', $searchTerm); $fieldQuery->setFieldOperator('allField', 'AND'); $fieldQuery->setFieldMinimumShouldMatch('allField', '80%'); $fieldQuery->setFieldAnalyzer('allField', 'custom_search_analyzer'); $boolQuery->addMust($fieldQuery); } $query = new \Elastica\Query(); $query->setQuery($boolQuery); $totalpages = ceil(count($finder->find($query)) / 12); $query->setSize(100); $query->setFrom($pageOffset); $articles = $finder->find($query); foreach ($articles as $article) { $variants = $article->getVariants(); foreach ($variants as $variant) { $price = $em->getRepository('OrthIndexBundle:ArticleSuppliers')->getCustomPrice(array('id' => $variant), $user); $category = $em->getRepository('OrthIndexBundle:Categories')->getRootCategory($article->getCategory()->getId()); $attribute = ""; foreach ($variant->getVariantvalues() as $values) { $attribute .= " " . $values->getAttrname()->getAttributeName() . " " . $values->getAttributeValue() . "" . $values->getAttributeUnit(); } if ($variant->getVariantvalues()) { if ($article->getImages()[0]) { $image = $article->getImages()[0]->getPicName(); } else { $image = 'nopicture_all.jpg'; } $result[] = array('shortName' => $article->getShortName() . "" . $attribute, 'articleNumber' => $variant->getSupplierArticleNumber(), 'price' => $price, 'category' => $category, 'image' => $image); } } } return $this->render('OrthIndexBundle:Oci:ocioutput.html.twig', array('results' => $result, 'page' => $page, 'totalpages' => $totalpages, 'hookurl' => $hookurl)); }
public function search($category, PlaceSearch $placeSearch) { // we create a query to return all the articles // but if the criteria title is specified, we use it $boolQuery = new \Elastica\Query\Bool(); /*Fetch only VALIDATED place*/ $queryStatus = new \Elastica\Query\Match(); $queryStatus->setFieldQuery('place.status', StatusType::VALIDATED); $boolQuery->addMust($queryStatus); if ($category !== null) { $queryCategory = new \Elastica\Query\Match(); $queryCategory->setFieldQuery('place.categories.slug', $category); $boolQuery->addMust($queryCategory); } if ($placeSearch->getBirthdayDiscount() != null && $placeSearch->getBirthdayDiscount() > 0) { $queryRange = new \Elastica\Query\Range(); $queryRange->setParam('place.birthdayDiscount', ['gte' => 1]); $boolQuery->addMust($queryRange); } if (($placeSearch->getName() != null || $placeSearch->getCategories() != null) && $placeSearch != null) { if ($placeSearch->getName() != null) { $query = new \Elastica\Query\Match(); $query->setFieldQuery('place.name', $placeSearch->getName()); $query->setFieldFuzziness('place.name', 1); $query->setFieldMinimumShouldMatch('place.name', '10%'); $boolQuery->addMust($query); } if ($placeSearch->getCategories() != null) { foreach ($placeSearch->getCategories() as $cat) { $categories[] = $cat->getName(); } $queryCategories = new \Elastica\Query\Terms(); $queryCategories->setTerms('place.categories', $categories); $boolQuery->addShould($queryCategories); } } else { $query = new \Elastica\Query\MatchAll(); } $baseQuery = $boolQuery; // then we create filters depending on the chosen criterias $boolFilter = new \Elastica\Filter\Bool(); $active = new \Elastica\Filter\Term(['membershipSubscriptions.statusSubscription' => MembershipStatusType::ACTIVE]); $boolFilter->addMust($active); /* Dates filter We add this filter only the getIspublished filter is not at "false" */ // if("false" != $articleSearch->getIsPublished() // && null !== $articleSearch->getDateFrom() // && null !== $articleSearch->getDateTo()) // { // $boolFilter->addMust(new \Elastica\Filter\Range('publishedAt', // array( // 'gte' => \Elastica\Util::convertDate($articleSearch->getDateFrom()->getTimestamp()), // 'lte' => \Elastica\Util::convertDate($articleSearch->getDateTo()->getTimestamp()) // ) // )); // } $boolQuery->addMust(new \Elastica\Query\Range('businessHours.startsAt', array('lte' => 'now'))); // $boolQuery->addMust(new \Elastica\Query\Range('businessHours.startsAt', // array( // //'gte' => \Elastica\Util::convertDate($articleSearch->getDateFrom()->getTimestamp()), // 'lte' => 'now' // )) // ); // // Published or not filter if ($placeSearch->getIs24h() !== null && $placeSearch->getIs24h()) { //var_dump($placeSearch->getIs24h());die(); $boolFilter->addMust(new \Elastica\Filter\Term(['is24h' => $placeSearch->getIs24h()])); //$boolFilter->addMust('is24h', $placeSearch->getIs24h()); } if ($placeSearch->getIsWifi() !== null && $placeSearch->getIsWifi()) { $boolFilter->addMust(new \Elastica\Filter\Term(['isWifi' => $placeSearch->getIsWifi()])); } if ($placeSearch->getIsDelivery() !== null && $placeSearch->getIsDelivery()) { $boolFilter->addMust(new \Elastica\Filter\Term(['isDelivery' => $placeSearch->getIsDelivery()])); } //$boolFilter->addMust($active); // $boolFilter->addMust( // new \Elastica\Filter\Term(['place.membershipSubscriptions.statusSubscription' => MembershipStatusType::ACTIVE]) // ); //var_dump($boolFilter);die(); //new \Elastica\Query\ $filtered = new \Elastica\Query\Filtered($baseQuery, $boolFilter); $query = \Elastica\Query::create($filtered); $query->addSort(array('place.membershipSubscriptions.membership.score' => array('order' => 'asc'))); //$query->addSort(array('rating' => array('order' => 'desc'))); var_dump(json_encode($query->getQuery())); die; return $this->find($query); //$qSort = \Elastica\Query::create($filtered); //$query = new \Elastica\Query(); //$query->setQuery($filtered); //$query->setQuery($qSort); //$query->setQuery($fnScoreQuery); //$fnScoreQuery->setQuery($filtered); //$qSort->setQuery($filtered); //return $this->find($query); }