Source of file FulltextRelevanceFilter.php
Size: 1,280 Bytes - Last Modified: 2021-12-24T06:48:26+00:00
/var/www/docs.ssmods.com/process/src/src/ORM/Filters/FulltextRelevanceFilter.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?php namespace Fromholdio\FulltextFilters\ORM\Filters; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\Filters\FulltextFilter; class FulltextRelevanceFilter extends FulltextFilter { 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()}')", $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'; } } |