In my mysql database I have texts full of apostropes which are used as stress marks. I need to implement keyword search ignoring these marks.
I tested it first by using direct sql in PhpMyAdmin:
SELECT * FROM `drupal_corpus_text` WHERE replace(text, "'", "") LIKE "%sinka%"
It perfectly finds the record containing sin'ka
.
But I cannot figure how to do it using Drupal features.
Here is what I try to do:
$apostrophe = "'";
$query = db_select('corpus_text', 'n')
->fields('n', array('text_id', 'speaker', 'text'))
->condition('n.text', '%' . db_like($key_search) . '%', 'LIKE')
->orderBy('speaker', 'ASC');
$query->addExpression('REPLACE(n.text, "'.$apostrophe.'", "")');
$query->execute();
And here is the error I get:
PDOException: SQLSTATE[42S22]:
Column not found: 1054 Unknown column ''' in 'field list':
SELECT n.text_id AS text_id, n.speaker AS speaker, n.text AS text,
REPLACE(n.text, "'", "") AS expression FROM {corpus_text} n
WHERE (n.text LIKE :db_condition_placeholder_0 ESCAPE '\\') ORDER BY speaker ASC
I cannot figure out how I must properly use all the quotes and the apostrophe mark to make it work.
The symbol used in those texts is U+0027.