I am trying to create a weighted search using doctrine. This is how i do it in straight sql. Im wondering how i would convert it to us the doctrine2 methods. I am trying to do this search using symfony2.
Also if there is a better way to do this I am open to that to. Thanks.
"SELECT *,
IF(`name` LIKE "%$searchterm%", 20,
IF(`name` LIKE "%$searchterm%", 10, 0)) +
IF(`address` LIKE "%$searchterm%", 5, 0) +
IF(`city` LIKE "%$searchterm%", 1, 0)
AS `weight`
FROM `table_name`
WHERE
(`name` LIKE "%$searchterm%" OR
`address` LIKE "%$searchterm%" OR
`city` LIKE "%$searchterm%")
ORDER BY `weight` DESC
LIMIT 20"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…