I use an exposed 'Search: Index' filter. The view should return an empty result when I submit a value that does not match any node. In reality, it displays all the nodes instead - as if the filter was not set. In case of complicated input (e.g. phrase search) the module behaves correctly, however. I'm attaching a very simple patch inspired by the way the module handles the complicated keywords conditions.

Comments

jennycita’s picture

Woo-hoo! This patch saved me a great deal of debugging. Works beautifully. Thanks!!

darren oh’s picture

Status: Needs review » Reviewed & tested by the community

Patch works well in my tests.

mikeryan’s picture

It breaks under Postgres with "Query failed: ERROR: argument of AND must be type boolean, not type integer".

Replace "0" with "FALSE", and it'll work for both MySQL and Postgres...

Thanks for tracking this down.

appel’s picture

Patch seems to work fine (with "0" replaced by "false"), thanks! Now if only I could make searching less strict...

Kripsy’s picture

Works just fine for me. Thank you.

darren oh’s picture

StatusFileSize
new766 bytes

Attached patch uses FALSE instead of 0.

claudiu.cristea’s picture

Tested. Works fine!

dmhouse’s picture

I've just come across this bug as well. Seems this issue has been open for almost 7 months now. The patch is sensible, works, and has been reviewed by the community. The bug is annoying and high-visibility. Any chance this could get committed?

By the way, you can work around this bug in code by doing a SELECT COUNT(*) FROM temp_search_sids; if there were no results, this query will return 0.

wOOge’s picture

Thanks you so much for this — it works perfectly!!

dmhouse’s picture

Correction: my above workaround doesn't function correctly in the case that you search for something that search_parse_query deems too small to be worth it, e.g. "to". Then temp_search_sids isn't created at all, and trying to select from it will give you an error. You can detect whether the table exists if you're running MySQL version 5.0.2 or greater you can use SHOW FULL TABLES LIKE "temp_search_sids" to check for its existence. Otherwise the only solution is to run search_parse_query again. For example, here's how I work around this issue:

$parsed = search_parse_query($_GET['filter0']);
if ($parsed === NULL || $parsed[0] == '' || $parsed[2] == ''
    || !count($nodes) 
    || !db_result(db_query('SELECT COUNT(*) FROM temp_search_sids'))) {

  // Search returned no results

}

So for this old, high-visibility bug (nearly everyone using Views search will come across it), there's no easy workaround and it's very confusing. But we have a simple, reviewed patch. Is no-one on this project watching the bugs? Can we commit it already?

jesss’s picture

This patch didn't work for me.

In searching for a fix, I also found this issue (#175066: No empty result with exposed Search: Index filter) which implies this behavior is by design. Why, I don't know...

Zoologico’s picture

I got around this using:

http://drupal.org/project/views_fastsearch

Instead of the default Search Index.

jesss’s picture

I did a fresh install of Views, and now the patch works.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.