public function testSearchCorrectSorting()
 {
     $sqlResult = array('\\Some\\Class' => array(3 => 1, 4 => 1), '\\Other\\Class' => array(12 => 2));
     $eventResult = array(new SearchResult('\\Some\\Class', 3, 'TestBundle', 'Test', 'test'), new SearchResult('\\Some\\Class', 4, 'TestBundle', 'Test', 'test'), new SearchResult('\\Other\\Class', 12, 'TestBundle', 'Test', 'test'));
     $repository = $this->getRepositoryMock($sqlResult);
     $eventDispatcher = $this->getEventDispatcherMock($eventResult);
     $search = new Search($repository, $eventDispatcher, 'test');
     $results = $search->search();
     // our items should still be here, because they are found in both sql and event
     $this->assertCount(3, $results);
     // the order should be from high weight to low weight
     $this->assertEquals(2, $results[0]->getWeight());
     $this->assertEquals(1, $results[1]->getWeight());
     $this->assertEquals(1, $results[2]->getWeight());
 }
 /**
  * @Route("/search.{_format}", defaults={"_format"="html"}, requirements={"_format"="html|json"})
  * @Template()
  */
 public function indexAction(Request $request)
 {
     $term = $request->get('term');
     $form = $this->createForm(new SearchType(), array('term' => $term));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         return $this->redirect($this->generateUrl('sumocoders_frameworksearch_default_index', array('term' => $data['term'])));
     }
     $results = null;
     if ('' != $term) {
         $repository = $this->getDoctrine()->getRepository('SumoCodersFrameworkSearchBundle:IndexItem');
         $dispatcher = $this->get('event_dispatcher');
         $search = new Search($repository, $dispatcher, $term);
         $results = $search->search();
     }
     if ('' != $term) {
         $this->get('framework.breadcrumb_builder')->addSimpleItem($term);
     }
     return array('term' => $term, 'form' => $form->createView(), 'results' => $results);
 }