Source of file SearchCriterion.php
Size: 5,060 Bytes - Last Modified: 2021-12-23T10:31:32+00:00
/var/www/docs.ssmods.com/process/src/src/Search/Criteria/SearchCriterion.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 | <?php namespace SilverStripe\FullTextSearch\Search\Criteria; use SilverStripe\Core\Injector\Injectable; use SilverStripe\FullTextSearch\Search\Adapters\SearchAdapterInterface; use SilverStripe\FullTextSearch\Search\Queries\AbstractSearchQueryWriter; /** * Class SearchCriterion * @package SilverStripe\FullTextSearch\Search\Criteria */ class SearchCriterion implements SearchCriteriaInterface { use Injectable; /** * field:value * * @var string */ const EQUAL = 'EQUAL'; /** * -field:value * * @var string */ const NOT_EQUAL = 'NOT_EQUAL'; /** * field:[value TO *] * * @var string */ const GREATER_EQUAL = 'GREATER_EQUAL'; /** * field:{value TO *} * * @var string */ const GREATER_THAN = 'GREATER_THAN'; /** * field:[* TO value] * * @var string */ const LESS_EQUAL = 'LESS_EQUAL'; /** * field:{* TO value} * * @var string */ const LESS_THAN = 'LESS_THAN'; /** * (field:value1 field:value2 field:value3) * * @var string */ const IN = 'IN'; /** * -(field:value1 field:value2 field:value3) * * @var string */ const NOT_IN = 'NOT_IN'; /** * field:[* TO *] * * @var string */ const ISNULL = 'ISNULL'; /** * -field:[* TO *] * * @var string */ const ISNOTNULL = 'ISNOTNULL'; /** * A custom Criterion with it's own SearchQueryWriter * * @var string */ const CUSTOM = 'CUSTOM'; /** * @var string */ protected $comparison; /** * The table and field that this Criterion is applied to. * * @var string */ protected $target; /** * @var mixed */ protected $value; /** * @var SearchAdapterInterface */ protected $adapter; /** * @var AbstractSearchQueryWriter */ protected $searchQueryWriter; /** * @param string $target * @param string|array $value * @param string|null $comparison * @param AbstractSearchQueryWriter $searchQueryWriter */ public function __construct( $target, $value, $comparison = null, AbstractSearchQueryWriter $searchQueryWriter = null ) { // EQUAL is our default comparison. if ($comparison === null) { $comparison = SearchCriterion::EQUAL; } $this->setTarget($target); $this->setValue($value); $this->setComparison($comparison); $this->setSearchQueryWriter($searchQueryWriter); } /** * @return SearchAdapterInterface */ public function getAdapter() { return $this->adapter; } /** * @param SearchAdapterInterface $adapter * @return $this */ public function setAdapter(SearchAdapterInterface $adapter) { $this->adapter = $adapter; return $this; } /** * @param string $ps * @return void * @throws \Exception */ public function appendPreparedStatementTo(&$ps) { $adapter = $this->getAdapter(); if (!$adapter instanceof SearchAdapterInterface) { throw new \Exception('No adapter has been applied to SearchCriteria'); } $ps .= $adapter->generateQueryString($this); } /** * String values should be passed into our filter string with quotation marks and escaping. * * @param string $value * @return string */ public function getQuoteValue($value) { if (is_string($value)) { return sprintf('"%s"', $value); } return $value; } /** * @return AbstractSearchQueryWriter */ public function getSearchQueryWriter() { return $this->searchQueryWriter; } /** * @param AbstractSearchQueryWriter $searchQueryWriter * @return $this */ public function setSearchQueryWriter($searchQueryWriter) { $this->searchQueryWriter = $searchQueryWriter; return $this; } /** * @return string */ public function getComparison() { return $this->comparison; } /** * @param string|null $comparison * @return $this */ protected function setComparison($comparison) { $this->comparison = $comparison; return $this; } /** * @return string */ public function getTarget() { return $this->target; } /** * @param string $target * @return $this */ protected function setTarget($target) { $this->target = $target; return $this; } /** * @return string|array */ public function getValue() { return $this->value; } /** * @param string|array $value * @return $this */ protected function setValue($value) { $this->value = $value; return $this; } } |