diff -r d2fba1e3b94b -r 21fab44f46fe Search/Search.php --- a/Search/Search.php Wed Nov 09 16:25:13 2011 +0100 +++ b/Search/Search.php Thu Nov 17 11:29:26 2011 +0100 @@ -42,6 +42,38 @@ } return $this->doctrine; } + /** + * + * Enter description here ... + * @param string $value + * @param array $conditions + * @param array $fields + */ + public function search($value, array $conditions, array $fields=null) + { + if(is_null($fields)) + { + $fields = $this->getContainer()->getParameter("wiki_tag.fields"); + } + $doctrine = $this->getContainer()->get('doctrine'); + $res = $doctrine->getRepository('WikiTagBundle:Document'); + $fieldquery = array(); + foreach ($fields as $fieldname => $fielddef) { + if(isset($fielddef['weight'])) + { + $weight = $fielddef['weight']; + } + else + { + $weight = 1.0; + } + $fieldquery[] = array("columns"=>$fieldname, "value"=>$value, "weight"=>$weight); + } + + $score_res = $res->search($fieldquery, $conditions); + + return $score_res; + } /** * Service to reorder the tags using their notes in the index search @@ -50,31 +82,14 @@ public function reorderTagsForDocument($document) { $doctrine = $this->getContainer()->get('doctrine'); - $res = $doctrine->getRepository('WikiTagBundle:Document'); + $tags_score = array(); + foreach($document->getTags() as $tag) { $label = $tag->getTag()->getLabel(); - // - $fields = $this->getContainer()->getParameter("wiki_tag.fields"); - - $fieldquery = array(); - foreach ($fields as $fieldname => $fielddef) { - $columns = "$fieldname"; - $value = $label; - if(isset($fielddef['weight'])) - { - $weight = $fielddef['weight']; - } - else - { - $weight = 1.0; - } - $fieldquery[] = array("columns"=>$columns, "value"=>$value, "weight"=>$weight); - } - - $score_res = $res->search($fieldquery, array("id"=>$document->getId())); + $score_res = $this->search($label, array("id"=>$document->getId())); if(count($score_res)>0) { @@ -104,12 +119,20 @@ public function getTagCloud($max_tags) { - $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); - $qb->select('t', 'COUNT( dt.id ) AS nb_docs'); - $qb->from('WikiTagBundle:Tag','t'); - $qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag'); - $qb->addGroupBy('t.id'); - $qb->addOrderBy('nb_docs','DESC'); + $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag'); + return $rep->getTagCloud($max_tags); + } + + public function completion($seed) + { + $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag'); + + $res = array(); + foreach ($rep->getCompletion($seed) as $value) { + $res[] = $value['label']; + } + + return $res; }