equal
deleted
inserted
replaced
145 if($nb_tags > 0) { |
145 if($nb_tags > 0) { |
146 throw new WikiTagServiceException(sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label), 400, null, "duplicate_tag"); |
146 throw new WikiTagServiceException(sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label), 400, null, "duplicate_tag"); |
147 } |
147 } |
148 // returns array($tag, $revision_id, $created) |
148 // returns array($tag, $revision_id, $created) |
149 try { |
149 try { |
150 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->getContainer()->getParameter('wiki_tag.ignore_wikipedia_error')); |
150 $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->getContainer()->getParameter('wiki_tag.ignore_wikipedia_error'), $this->getContainer()->get('logger')); |
151 } |
151 } |
152 catch (\Exception $e){ |
152 catch (\Exception $e){ |
153 throw new WikiTagServiceException($e->getMessage(), 500 , $e, "wikipedia_request_failed"); |
153 throw new WikiTagServiceException($e->getMessage(), 500 , $e, "wikipedia_request_failed"); |
154 } |
154 } |
155 |
155 |
194 throw new WikiTagServiceException("Unknown document id"); |
194 throw new WikiTagServiceException("Unknown document id"); |
195 } |
195 } |
196 |
196 |
197 return $rep->getTagsStr($doc); |
197 return $rep->getTagsStr($doc); |
198 } |
198 } |
|
199 |
|
200 /** |
|
201 * Service to reorder the tags using their notes in the index search. |
|
202 * This service is configured in the configuration file by affecting the weight in each field definition. |
|
203 * |
|
204 * @param IRI\Bundle\WikiTagBundle\Model\DocumentInterface $document |
|
205 */ |
|
206 public function reorderTags($document) |
|
207 { |
|
208 $doctrine = $this->getContainer()->get('doctrine'); |
|
209 |
|
210 $tags_score = array(); |
|
211 |
|
212 foreach($document->getTags() as $tag) |
|
213 { |
|
214 $label = $tag->getTag()->getLabel(); |
|
215 |
|
216 $score_res = $this->search($label, array("id"=>$document->getId())); |
|
217 |
|
218 if(count($score_res)>0) |
|
219 { |
|
220 $score = floatval($score_res[0]['score']); |
|
221 } |
|
222 else |
|
223 { |
|
224 $score = 0.0; |
|
225 } |
|
226 $tags_score[] = array($score,$tag); |
|
227 } |
|
228 // sort tags based on score |
|
229 $i=1; |
|
230 usort($tags_score, function($a, $b) { |
|
231 return $a[0]<$b[0]?1:-1; |
|
232 }); |
|
233 |
|
234 foreach($tags_score as $item) |
|
235 { |
|
236 $tag = $item[1]; |
|
237 $tag->setTagOrder($i++); |
|
238 $tag->setIndexNote($item[0]); |
|
239 $doctrine->getEntityManager()->persist($tag); |
|
240 } |
|
241 |
|
242 } |
|
243 |
199 |
244 |
200 } |
245 } |