Doctrine 2: Using query builder for to query a variable number of fields/associations for advanced search
i'm trying to build a repo function to search a entity which has a few associations. My question is, what is an efficient manner for doing this? If I have a project entity with an association to a user e开发者_JS百科ntity, for example, and allow my users to search for projects by project name, user name, user company, etc. etc. In this case, I may need to join the user entity in order to setup where clauses. I won't always need to however, so I would need to setup the join only if someone wants to search for user entity properties. Should I just do a conditional stmt to see if any user entity properties are being searched for, and only then do invoke the join and andWhere methods of the qb? Or is there another way to do this? Thx!
Using conditionals and adding joins and where's should work fine for a basic searching feature as you described.
I've used something similar myself and it suffices as long as you don't need more advanced keyword matching or such.
If you need something more complicated, or need better performance, you probably should consider using a real fulltext search engine like Lucene, or Solr and ElasticSearch may be easier to use from PHP than raw Lucene on its own.
精彩评论