I'm using the Searchable behavior in Doctrine to search for products in my catalog. It works great when searching for keywords that do match a product. For example, the keyword "Backpack" returns all products with the word "Backpack" in the title开发者_开发技巧.
However, when a search is done for a keyword that doesn't match a title at all then every record is returned. For example, "ASDF" returns all products.
Why is this happening and how can I fix it?
I had this same issue when using Lucene. If I recall correctly the reason it occurred was because lucene returns a list of IDs that match the parameters queried. And if none are returned then Doctrine has no criteria on which to search by therefore queries without a where clause.
In your action I expect you'll probably have a call to Lucene to find matching products, and then a call using those results as criteria to retrieve them; I solved the problem by whacking an if around the main query checking that the Lucene has returned something useful.
精彩评论