Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Fulltext.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class Fulltext
11 {
15  const FULLTEXT_MODE_NATURAL = 'IN NATURAL LANGUAGE MODE';
16 
20  const FULLTEXT_MODE_NATURAL_QUERY = 'IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION';
21 
25  const FULLTEXT_MODE_BOOLEAN = 'IN BOOLEAN MODE';
26 
30  const FULLTEXT_MODE_QUERY = 'WITH QUERY EXPANSION';
31 
35  const MATCH = 'MATCH';
36 
40  const AGAINST = 'AGAINST';
41 
45  private $connection;
46 
51  {
52  $this->connection = $resource->getConnection();
53  }
54 
63  public function getMatchQuery($columns, $expression, $mode = self::FULLTEXT_MODE_NATURAL)
64  {
65  if (is_array($columns)) {
66  $columns = implode(', ', $columns);
67  }
68 
69  $expression = $this->connection->quote($expression);
70 
71  $condition = self::MATCH . " ({$columns}) " . self::AGAINST . " ({$expression} {$mode})";
72  return $condition;
73  }
74 
86  public function match($select, $columns, $expression, $isCondition = true, $mode = self::FULLTEXT_MODE_NATURAL)
87  {
88  $fullCondition = $this->getMatchQuery($columns, $expression, $mode);
89 
90  if ($isCondition) {
91  $select->where($fullCondition);
92  } else {
93  $select->orWhere($fullCondition);
94  }
95 
96  return $select;
97  }
98 }
$resource
Definition: bulk.php:12
$columns
Definition: default.phtml:15
__construct(ResourceConnection $resource)
Definition: Fulltext.php:50
getMatchQuery($columns, $expression, $mode=self::FULLTEXT_MODE_NATURAL)
Definition: Fulltext.php:63
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
match($select, $columns, $expression, $isCondition=true, $mode=self::FULLTEXT_MODE_NATURAL)
Definition: Fulltext.php:86