Re: Free text search in MySQL
From: Thomas 'PointedEars' Lahn <PointedEars_at_web.de>
Date: Thu, 31 Mar 2016 20:25:40 +0200
Message-ID: <3114073.WFD38WVuFh_at_PointedEars.de>
>
> Beware that this also matches words or phrases like 'Democrat',
> 'movie rating', and 'proration'. If you put spaces around the word
> in the query, you will fail to find mentions of that word that begin
> or end the entry, or where the word has punctuation instead of a
> trailing space.
Date: Thu, 31 Mar 2016 20:25:40 +0200
Message-ID: <3114073.WFD38WVuFh_at_PointedEars.de>
>>> If I have the text "A rat in a hat" inside a MySQL DB, and if on my >>> webpage someone searches for the text "rat", I would like them to get >>> that line - how do I do that? I realise that this sort of *precludes* my >>> previous question about fuzzy matching, but I would still like to >>> know.... >> >> SELECT column FROM table WHERE text_key_column LIKE '%rat%';
>
> Beware that this also matches words or phrases like 'Democrat',
> 'movie rating', and 'proration'. If you put spaces around the word
> in the query, you will fail to find mentions of that word that begin
> or end the entry, or where the word has punctuation instead of a
> trailing space.
Reminds me of “The Boscombe Valley Mystery” :)
> Some forms of regular expressions have a better facility for matching
> "word boundaries" for some reasonable definition of the term, useful
> if your database provides that.
I do not know if this is in total more expensive than proper regular
expression matching, which would be
SELECT `column` FROM `table`
in MySQL. Conciseness can one deceive over the underlying complexity.
<http://dev.mysql.com/doc/refman/5.7/en/regexp.html#operator_regexp>
WHERE `text_key_column` REGEXP "[[:<:]]rat[[:>:]]";
> Take the contents of the Subject and Text Body, split it into
> words, […]
-- PointedEars Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953> | Twitter: _at_PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.Received on Thu Mar 31 2016 - 20:25:40 CEST