Search code examples
symfony1doctrinesearchable

Symfony/Doctrine Searchable Behavior : How to override search function?


Here is the thing, I have implemented the searchable behavior on my symfony project and it's working fine. The problem is when I try to perform a search with two words or more. The query generated by the search function is like:

SELECT COUNT(keyword) AS relevance, id FROM table_index 
WHERE id IN (SELECT id FROM table_index WHERE keyword = 'foo') 
AND id IN (SELECT id FROM table_index WHERE keyword = 'bar') 
GROUP BY id 
ORDER BY relevance DESC

Because the search uses a AND clause, these two words have to be part of a same item to be relevant. Though to modify the behavior of the search I would like to override the search function. But because the table_index generated by doctrine is not declared on my schema.yml, I'm not able to perform query on it.

Is there an other way to do it ?? Thanks


Solution

  • Ok, my bad, I thought that accessing the table_index was impossible because not declared on my schema.yml, but actually it is, thanks to the searchable line.

    In my search function,Instead of

    $q = Doctrine_Query::create()
      ->select('COUNT(e.keyword) AS relevance, e.id')
       ->from('Table_Index t');
    

    I just had to remove the _ in the name of the index table

    $q = Doctrine_Query::create()
      ->select('COUNT(e.keyword) AS relevance, e.id')
       ->from('TableIndex t');