diff -r 989d9e117586 -r e7384fb35f7a Services/DocumentService.php --- a/Services/DocumentService.php Mon Dec 26 22:53:50 2011 +0100 +++ b/Services/DocumentService.php Mon Jan 23 00:48:55 2012 +0100 @@ -147,7 +147,7 @@ } // returns array($tag, $revision_id, $created) try { - $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->getContainer()->getParameter('wiki_tag.ignore_wikipedia_error')); + $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->getContainer()->getParameter('wiki_tag.ignore_wikipedia_error'), $this->getContainer()->get('logger')); } catch (\Exception $e){ throw new WikiTagServiceException($e->getMessage(), 500 , $e, "wikipedia_request_failed"); @@ -196,5 +196,50 @@ return $rep->getTagsStr($doc); } + + /** + * Service to reorder the tags using their notes in the index search. + * This service is configured in the configuration file by affecting the weight in each field definition. + * + * @param IRI\Bundle\WikiTagBundle\Model\DocumentInterface $document + */ + public function reorderTags($document) + { + $doctrine = $this->getContainer()->get('doctrine'); + + $tags_score = array(); + + foreach($document->getTags() as $tag) + { + $label = $tag->getTag()->getLabel(); + + $score_res = $this->search($label, array("id"=>$document->getId())); + + if(count($score_res)>0) + { + $score = floatval($score_res[0]['score']); + } + else + { + $score = 0.0; + } + $tags_score[] = array($score,$tag); + } + // sort tags based on score + $i=1; + usort($tags_score, function($a, $b) { + return $a[0]<$b[0]?1:-1; + }); + + foreach($tags_score as $item) + { + $tag = $item[1]; + $tag->setTagOrder($i++); + $tag->setIndexNote($item[0]); + $doctrine->getEntityManager()->persist($tag); + } + + } + } \ No newline at end of file