tags:

views:

103

answers:

1

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?

A: 

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.

Steve
Wrapping an if statement around the main query to see if Doctrine returned anything solved the problem. Thanks for your help.
JonP