I've seen some other people on drupal.org and drupalcenter.de with the same problem and nobody has an answer till yet. I worked a bit in the search.module code to find a solution. In my opinion the problem is in line 764 in the '_search_parse_query' function because i built my own query to get data and found out that the query has to look like this '%%word%%' and not '%% word %%' (in code '%% %s %%'). After a night with many tests I've given up and decided to ask for a solution here.

Thanks a lot.

Comments

mbchandar’s picture

Assigned: Unassigned » mbchandar

hi,

here is the patch for search.module

*** modules/search.module 2006-05-10 13:51:44.000000000 +0530
--- modules/search.module1 2006-05-10 12:54:45.000000000 +0530
***************
*** 360,364 ****
// With the exception of the rules above, we consider all punctuation,
// marks, spacers, etc, to be a word boundary.
! //$text = preg_replace('/['. PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $text);

return $text;
--- 360,364 ----
// With the exception of the rules above, we consider all punctuation,
// marks, spacers, etc, to be a word boundary.
! $text = preg_replace('/['. PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $text);

return $text;
***************
*** 737,741 ****

// Build word-index conditions for the first pass
! $query2 = substr(str_repeat("i.word like '%s' OR ", count($arguments2)), 0, -4);

return array($query, $arguments, $query2, $arguments2, $matches);
--- 737,741 ----

// Build word-index conditions for the first pass
! $query2 = substr(str_repeat("i.word = '%s' OR ", count($arguments2)), 0, -4);

return array($query, $arguments, $query2, $arguments2, $matches);

here is the patch for node.module

*** modules/node.module 2006-05-10 12:55:24.000000000 +0530
--- modules/node.module1 2006-05-10 12:53:44.000000000 +0530
***************
*** 698,702 ****

// Do search
- $keys=str_replace("*","%",$keys);
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1 .' INNER JOIN {users} u ON n.uid = u.uid', $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2);

--- 698,701 ----

save this patch and patch the node.module and search.module file.

it will work

aamercado’s picture

I need search with wildcards in drupal 4.7!, y tried the patch but not work for me. Any solution? Thanks and sorry for my english!...

Creazion’s picture

@ mbchandar:

thx for the fast support, your patch works great on the site www.happy-faces.de and sorry for my late answer.

RobRoy’s picture

@mbchandar: Can you submit a proper patch according to http://drupal.org/diffandpatch ? I'm not sure if completely commenting out that first line is the way to go as it will remove all word boundary catching?

Steven’s picture

Status: Active » Closed (won't fix)

Wildcard support was removed intentionally. It destroyed database performance. Stemming is preferred instead.

RobRoy’s picture

So is stemming in place currently? What should users do if they want wildcard functionality at the sake of a huge db hit?

whereisian’s picture

I tried to apply the patch but got the following:

for search.module.patch:

patch: **** malformed patch at line 5: // With the exception of the rules above, we consider all punctuation,

for node.module.patch:

patch: **** malformed patch at line 6: // Do search

Any ideas? Stemming won't do for the type of searches we need.

giorgosk’s picture

post #1 patch means

in search.module

comment out line 362 out like this
//$text = preg_replace('/['. PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $text);

replace "=" with "like" in line 739 like this
$query2 = substr(str_repeat("i.word like '%s' OR ", count($arguments2)), 0, -4);

and

add following line after line 699 in node.module
$keys=str_replace("*","%",$keys);

so if patching is not working for you go ahead and patch both modules by hand