2013-05-06 81 views
2

我需要使用相同字符串對多個實體執行搜索,然後對結果進行排序。如何使用Symfony 2在多個實體上執行搜索

我聽說/讀了一些關於FOSElasticaBundle,這個包是否能夠做到這一點?在我看來,爲了達到這個目的,幾乎有很多功能,我不確定它可以在共享服務器上運行(hostgator)。

其他解決方案,我可以在那一刻想到的是做搜索「手動」(通過使用joinunion),但我想知道我應該把這樣的功能:在現有的控制器,一個新的,一個新的包或其他地方? 我擔心,以及本手冊的解決方案能來有成本的,特別是對一些不可索引的字段。

回答

0

你會做自定義實體存儲庫。檢出the docs。基本上,這擴展了默認的FindAll,FindOneBy等

你將不得不像這樣的功能:

class MyEntityRepository extends Doctrine\ORM\EntityRepository { 
    public function findByCustomRule(){ 
     //this is mapped to your entity (automatically adds the select) 
     $queryBuilder = $this->createQueryBuilder('someAlias'); 
     $queryBuilder->orderBy('...'); 

     //this is mapped to any entity 
     $queryBuilder = $this->getEntityManager()->createQueryBuilder(); 
     $queryBuilder->select('...'); 


     //result 
     $result = $queryBuilder->getQuery()->getResult(); 

    } 
} 

此類學說中所映射定義和生命的實體文件夾內。檢查的文檔了你應該有一個基本的想法。

相關問題