Download & Extend

Searching multiple words in the keyword block (unexpected non-alpha-numeric character handling)

Project:Faceted Search
Version:6.x-1.0-beta2
Component:General
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

My current set up:
Apache
PHP 5.2.11
MySQL 5.0.81
Drupal 6.13
Faceted search 6.x-1.0-beta2

This is the first time I have used this module and I am getting unexpected results when using non-alpha-numeric characters like spaces in the keyword search block.
This could be by design but I have not found any reference to this in the readme or anywhere else.

If I search for two words separated by a space I get a white screen.
If I search for two words separated by a forward slash I get search results for the two words ORed (what I would have expected from two words separated by a space).
If my search has pretty much any other symbol in it I get a white screen. For example #$()+[] etc.

Symbols are valid search characters and having to use slashes instead of spaces is very unusual.
I have never seen a search system fail when using symbols and I suspect my sites users would have no idea what is going on.

Is this the modules functionality (if so, for what reason?) or is this unexpected behavior that is being caused by my setup somehow?

Thanks

Comments

#1

It seems to be related to this specific site as I have tried it on a brand new drupal install and I don't get the white screen problem.

Although it does seem to strip out a lot of punctuation.

#2

Category:bug report» support request

I've now narrowed it down to the host. An exact copy of the site copied to a different server works correctly.

If anyone else has seen this behavior before and knows anything about it I'm open to suggestions.

#3

I have updated to Drupal 6.14 so my current set up is:
Apache
PHP 5.2.11
MySQL 5.0.81
Drupal 6.14
Faceted search 6.x-1.0-beta2

Also, there is nothing in the watchdog log or the apache error log.

#4

I have further narrowed it down to line 414 of faceted_search.module

There is something going on in that uasort call and its comparison function _faceted_search_compare_filters that is causing me to get a white screen, but not on all servers.

#5

I have tracked this further now. I'm documenting it here in case anyone else has this odd problem.

It seems from my testing the problem is on line 451 of faceted_search.inc which is:

<?php
 
return $this->check_label(theme('faceted_search_keyword_and_label', $this->_word), $html);
?>

To be more particular, I isolated the problem to

<?php
  theme
('faceted_search_keyword_and_label', $this->_word)
?>

If I remove that part it works.
If I move that part out like this:

<?php
  $word
= theme('faceted_search_keyword_and_label', $this->_word);
  return
$this->check_label($word, $html);
?>

it doesn't work unless I comment out the line that calls theme().
It doesn't matter what is in the variable that gets sent to theme_faceted_search_keyword_and_label, it always seems to fail.

If you have this problem and you don't car about being able to theme that label text you can get around it by changing
the function get_label (line 450 of faceted_search.inc - there are other get_label functions that may or may not cause the same problem) to:

<?php
 
function get_label($html = FALSE) {
//    For some reason calling this theme function causes a crash when searching more than one word.
//    The theme function only does a check_plain so if the theme doesn't need to be overrided just skip the theme function.
//    return $this->check_label(theme('faceted_search_keyword_and_label', $this->_word), $html);
   
return $this->check_label(check_plain($this->_word), $html);
  }
?>

(the comments are just there so you know what is going on)

Does anyone have any idea what might cause this call to theme() to be a problem on one server and not another?
It is really strange.

#6

Are you using "Zen" theme (or a sub-theme)?

I'm having the same issue but it only seems to happen for me if I'm using a variation of Zen.

I'm going to keep investigating.

#7

It's actually a modified version of the acquia_slate theme

#8

Yeah, never mind, I seem to be getting the error with all themes now. But as you mentioned it seems to be something that happens on one server and not another. I have a clone of my Drupal installation and database running on another machine with no problems! Both machines are Macs running MAMP, its really bizarre.

#9

Yes, I was having this exact problem. Our theme is a modified version of Zen. Your fix worked fine for me...

#10

Category:support request» bug report

I thought maybe it was a problem specific to my setup because no one had posted this issue before and it was very specific but it seems it is a problem.

#11

Had the same problem and this patch fixed it for me as well.

#12

Same problem and the patch in #5 fixed it for me also. Could this get committed or fixed in some other way?

#13

I would think the maintainer would be unlikely to commit the fix mentioned in #5 because it removes the ability to override the theming using
theme_faceted_search_keyword_and_label

I don't know what other solution there is though because I don't really know the true cause of the problem.

Someone could always roll a patch for the fix in #5 and see what the maintainer says.

#14

I'm also getting a related problem. No white screen, but the following warning shows up whenever searching for anything with a space:

warning: uasort() [function.uasort]: Array was modified by the user comparison function in [...]/sites/all/modules/faceted_search/faceted_search.module on line 414.

Using the patch in #5 also fixes the problem for me. (Thanks Agileware!)

Host: HostGator
PHP: 5.2.4
Drupal: 6.20
Faceted Search: 6.x-1.0-beta2
Theme: Custom, but based on Zen

#15

i had the exact same problem intermittently and after some digging found that the second parameter of the uasort function on line 414 of faceted_search.module was the culprit. The uasort function basically allows you to sort an array and specify a user defined callback function to do so. I found two utility functions at the end of faceted_search.module so what I did is use the second one instead of the first utility function and it solved my problem. This ends up sorting the filters used by weight only but did the trick for my purposes.

when using multiple keywords in the first function for faceted search you'll notice that it sorts the filters alphabetically it will no longer do so when modifying the original callback used. You can define your own if you need to though.

used:

<?php
uasort
($filters, '_faceted_search_element_sort');
?>

instead of:

<?php
uasort
($filters, '_faceted_search_compare_filters');
?>
nobody click here