On Mon, 3 Sep 2001, Chris Cameron wrote:

> I'm sure this is disscused somewhere, but I'm not sure how I'd look for
> it.
>
> Is it possible to supply a thesaurus-like file for mysql so when you
> go "%oil%" it finds petrol gas and/or lubricant?

As far as I know, there is no way to do that natively in MySQL. It's
relatively easy for you to write a wrapper function to do this, though.
Assuming you're working in perl, you can do something like this:

# WHERE data LIKE '%oil%' => thesaurus('data', 'oil')
sub thesaurus {
  my ($column, $word) = shift;
  return join(' OR ', map { "$column LIKE '%$_->[0]%' }
$dbh->selectall_arrayref("SELECT words FROM thesaurus WHERE key=?", $word);
}

So thesaurus('data', 'oil') would return:
  data LIKE '%petroleum%' OR data LIKE '%gas%' OR data LIKE '%oil%'
and you can use that as part of your SQL query.


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to