2008-08-06 05:28:25 +02:00
|
|
|
<?php
|
2008-08-09 08:40:50 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-09 08:40:50 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
|
2008-08-06 05:28:25 +02:00
|
|
|
/**
|
2008-08-09 06:38:44 +02:00
|
|
|
* Filters by full-text matching on the given field.
|
|
|
|
*
|
|
|
|
* Full-text indexes are only available with MyISAM tables. The following column types are
|
|
|
|
* supported:
|
|
|
|
* - Char
|
|
|
|
* - Varchar
|
|
|
|
* - Text
|
|
|
|
*
|
|
|
|
* To enable full-text matching on fields, you also need to add an index to the
|
|
|
|
* database table, using the {$indexes} hash in your DataObject subclass:
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-09 06:38:44 +02:00
|
|
|
* <code>
|
|
|
|
* static $indexes = array(
|
|
|
|
* 'SearchFields' => 'fulltext(Name, Title, Description)'
|
|
|
|
* );
|
|
|
|
* </code>
|
2008-08-06 05:28:25 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-06 05:28:25 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
2008-08-09 05:54:55 +02:00
|
|
|
class FulltextFilter extends SearchFilter {
|
2008-08-09 06:06:52 +02:00
|
|
|
|
2012-09-06 09:54:44 +02:00
|
|
|
protected function applyOne(DataQuery $query) {
|
2013-06-21 00:32:08 +02:00
|
|
|
$predicate = sprintf("MATCH (%s) AGAINST (?)", $this->getDbName());
|
|
|
|
return $query->where(array($predicate => $this->getValue()));
|
2008-08-09 06:06:52 +02:00
|
|
|
}
|
2008-08-09 06:38:44 +02:00
|
|
|
|
2012-09-06 09:54:44 +02:00
|
|
|
protected function excludeOne(DataQuery $query) {
|
2013-06-21 00:32:08 +02:00
|
|
|
$predicate = sprintf("NOT MATCH (%s) AGAINST (?)", $this->getDbName());
|
|
|
|
return $query->where(array($predicate => $this->getValue()));
|
2012-09-06 09:54:44 +02:00
|
|
|
}
|
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
public function isEmpty() {
|
2012-09-06 09:54:44 +02:00
|
|
|
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
2008-08-11 02:03:57 +02:00
|
|
|
}
|
2008-08-06 05:28:25 +02:00
|
|
|
}
|