| | 140 | ++ Performing Searches |
| | 141 | |
| | 142 | Here is a simple example to retrieve the record ids and relevance data. |
| | 143 | |
| | 144 | <code type="php"> |
| | 145 | $results = Doctrine::getTable('Article a')->search('php orm'); |
| | 146 | |
| | 147 | // Executes the following query and returns an associative array |
| | 148 | // SELECT COUNT(keyword) AS relevance, id FROM article_index WHERE id IN (SELECT id FROM article_index WHERE keyword = ?) AND id IN (SELECT id FROM article_index WHERE keyword = ?) GROUP BY id ORDER BY relevance DESC |
| | 149 | |
| | 150 | print_r($results); // Will print an array of record ids and the relevance of each |
| | 151 | </code> |
| | 152 | |
| | 153 | You can optionally pass the search() function a query object to modify with a where condition subquery to limit the results using the search index. |
| | 154 | |
| | 155 | <code type="php"> |
| | 156 | $query = Doctrine_Query::create() |
| | 157 | ->from('Article a'); |
| | 158 | |
| | 159 | $articles = Doctrine::getTable('Article a')->search('php orm', $query)->fetchArray(); |
| | 160 | |
| | 161 | // Executes the following query |
| | 162 | // SELECT a.id AS a__id, a.title AS a__title, a.body AS a__body FROM article a WHERE a.id IN(SELECT id FROM article_index WHERE id IN (SELECT id FROM article_index WHERE keyword = ?) && id IN (SELECT id FROM article_index WHERE keyword = ?) GROUP BY id) |
| | 163 | |
| | 164 | print_r($articles); // Will print the articles which have the keywords php or orm in them. |
| | 165 | </code> |
| | 166 | |