Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnott committed Jan 24, 2022
1 parent 1ae5c21 commit 7c4d0e0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
42 changes: 42 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,23 @@ public function selectRaw($expression, array $bindings = [])
return $this;
}

/**
* @param string|string[] $columns
* @param string $value
* @param string $as
* @return $this
*/
public function selectFullText($columns, $value, $as, array $options = [])
{
$columns = (array) $columns;

$query = $this->grammar->compileFullText($columns, $value, $options);

return $this->selectRaw(
'('.$query.') as '.$this->grammar->wrap($as), [$value]
);
}

/**
* Makes "from" fetch from a subquery.
*
Expand Down Expand Up @@ -415,6 +432,31 @@ public function addSelect($column)
return $this;
}

/**
* Add a fulltext select to the query.
*
* @param string|string[] $columns
* @param string $value
* @param string $as
* @return $this
*/
public function addSelectFullText($columns, $value, $as, array $options = [])
{
if (is_null($this->columns)) {
$this->select($this->from.'.*');
}

$columns = (array) $columns;

$query = $this->grammar->compileFullText($columns, $value, $options);

$this->selectSub($query, $as);

$this->addBinding([$value], 'select');

return $this;
}

/**
* Force the query to only return distinct results.
*
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,21 @@ public function whereFullText(Builder $query, $where)
throw new RuntimeException('This database engine does not support fulltext search operations.');
}

/**
* Compile a "fulltext" clause.
*
* @param array $columns
* @param string $value
* @param array $options
* @return string
*
* @throws \RuntimeException
*/
public function compileFullText($columns, $value, $options)
{
throw new RuntimeException('This database engine does not support fulltext search operations.');
}

/**
* Compile the "group by" portions of the query.
*
Expand Down
23 changes: 18 additions & 5 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,36 @@ protected function whereNotNull(Builder $query, $where)
}

/**
* Compile a "where fulltext" clause.
* Add a "where fulltext" clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
public function whereFullText(Builder $query, $where)
{
$columns = $this->columnize($where['columns']);
return $this->compileFullText($where['columns'], $where['value'], $where['options']);
}

/**
* Compile a "fulltext" clause.
*
* @param array $columns
* @param string $value
* @param array $options
* @return string
*/
public function compileFullText($columns, $value, $options)
{
$columns = $this->columnize($columns);

$value = $this->parameter($where['value']);
$value = $this->parameter($value);

$mode = ($where['options']['mode'] ?? []) === 'boolean'
$mode = ($options['mode'] ?? []) === 'boolean'
? ' in boolean mode'
: ' in natural language mode';

$expanded = ($where['options']['expanded'] ?? []) && ($where['options']['mode'] ?? []) !== 'boolean'
$expanded = ($options['expanded'] ?? []) && ($options['mode'] ?? []) !== 'boolean'
? ' with query expansion'
: '';

Expand Down

0 comments on commit 7c4d0e0

Please sign in to comment.