Source of file FulltextBooleanRelevanceFilter.php
Size: 1,265 Bytes - Last Modified: 2021-12-24T06:48:26+00:00
/var/www/docs.ssmods.com/process/src/src/ORM/Filters/FulltextBooleanRelevanceFilter.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | <?php namespace Fromholdio\FulltextFilters\ORM\Filters; use SilverStripe\ORM\DataQuery; class FulltextBooleanRelevanceFilter extends FulltextBooleanFilter { protected $weight; public function __construct(?string $fullName = null, $value = false, array $modifiers = array(), int $weight = 1) { parent::__construct($fullName, $value, $modifiers); $this->setWeight($weight); } protected function applyOne(DataQuery $query) { $query = parent::applyOne($query); $alias = $this->getRelevanceAlias(); $score = $this->getScoreName(); $select = sprintf("{$score} := MATCH (%s) AGAINST ('{$this->getValue()}' IN BOOLEAN MODE)", $this->getDbName()); $weight = $this->getWeight(); $select = $select . ' * ' . $weight; $query->selectField($select, $alias); return $query; } public function setWeight(int $weight) { $this->weight = $weight; return $this; } public function getWeight() { return (int) $this->weight; } public function getRelevanceAlias() { return $this->getName() . 'Relevance'; } public function getScoreName() { return '@' . $this->getName() . 'Score'; } } |