For the system I'm creating pages for some symbols have special functions. I have pages/nodes with those symbols as their title. @ and ! especially at issue because they appear in two different contexts (entirely different meaning in each), so there's two pages for each of them '@ (context A)' and '@ (context B)'.

When a user uses the Drupal Search, and searches solely on '@', those nodes should be in the search results. So far, I'm getting 'You must include at least one positive keyword with 0 characters or more.' when searching on the symbols, even after reducing the required word length to zero (I forced cron to run after doing so).

Does Drupal 6 strip out all or some of the symbols from the search text?

After playing with this for a while it occurred to me that since there's very few of these the approach might be to simply create a special case for them in the search. Is there a hook I could intercept in a module to handle the special cases? What's the best approach here? :)

Added Information:

To clarify, 'context A' and 'context B' were merely made up examples. the real thing would look more like: '@ (primitive)' and '@ (prefix)'. A search on '@' should turn up both, since the site has no way of knowing which (prefix or primitive) the user needs to know about.

  • Hi, maybe I didn't understand your question, so I have to ask. So, I created two nodes with the exact title "@ (context A)" and "@ (context B)" for a simple test (i.imgur.com/8PTNW.png). After that, I tried to do a regular node search, here are the results: i.imgur.com/sZjBA.png, so Drupal finds both of them, containing an at (@) sign. I also tried the same after renaming one of the nodes: i.imgur.com/3c4iD.png. Does your question mean that the same stuff doesn't work on your site?
    – Sk8erPeter
    Mar 27 '12 at 21:17
  • Okay that's strange. I'll go back and try again and try disabling various modules to see if there's a module I've installed that is getting in the way.
    – Iain
    Mar 28 '12 at 15:46
  • Oh. After some fiddling, I realized a difference between what we're doing. You searched on '@ (context' . I'm searching on '@' by itself. Currently, I'm getting this error "You must include at least one positive keyword with 0 characters or more."
    – Iain
    Mar 28 '12 at 16:07

Taking a fresh look at the problem this morning, I took a stab at finding out how to create a module to solve it. I think the search terms are run through 'check_plain', stripping it down to just text (no symbols).

Turns out that a module providing the hook_search_prepocess hook can override the text used by the indexer and the search. So I put together a module in which my hook does a replacement of '@' with 'atsign', which appears to solve the issue. Also means I can set the minimum word size back to '3', as long as my replacement text is 3 or more characters.

I now have a sites/all/modules/searchfix/searchfix.module file (and corresponding .info file), with the following function in it:

function searchfix_search_preprocess($text) {
    return str_replace("@", "atsign", $text);
  • @MPD I was thinking so, but I wasn't sure. I decided to wait a bit in case someone else had a better solution or refinements. 'course, I can always change the accepted answer if someone offers a better one.
    – Iain
    Mar 29 '12 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.