I need to display entries by searching a custom field like so:
{exp:channel:entries channel="my_channel" search:my_field="#{segment_2}\W" limit="20"}
Note the # sign. I'm specifically searching for hashtags.
If I leave off the \W it works just fine. But it does not always return the exact words – (eg. #cat also returns #catnap) – exactly as you'd expect.
So I really need that whole word feature to work.
I believe I've traced the breaking point down to the code below (approx. line 1145-1155 in mod.channel.php):
elseif (strpos($term, '\W') !== FALSE) // full word only, no partial matches
{
// Note: MySQL's nutty POSIX regex word boundary is [[:>:]]
$term = '([[:<:]]|^)'.preg_quote(str_replace('\W', '', $term)).'([[:>:]]|$)';
$fields_sql .= ' (wd.site_id=' . $site_id
. ' AND wd.field_id_' . $this->cfields[$site_id][$field_name] . ' ' . $not
. ' REGEXP "' . $this->EE->db->escape_str($term).'") '
. $andor;
}
Someone correct me if I'm wrong, but I think that REGEXP escape_str($term) bit is breaking it.
So I'm looking for a workaround. It would be best not to hack the code directly (of course), but this is the only time that function is being used on the site... So I'm not totally opposed to hacking a fix right there.
Any ideas?