Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Compound Full-Text Indexes #875

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/Engines/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,39 @@ protected function initializeSearchQuery(Builder $builder, array $columns, array

$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';

$fullTextColumnsChecked = [];

foreach ($columns as $column) {
if (in_array($column, $fullTextColumns)) {
if (in_array($column, $fullTextColumnsChecked)) {
continue;
}

if (in_array($column, Arr::flatten($fullTextColumns))) {
$fullTextColumnTarget = Arr::first(
$fullTextColumns,
fn ($entry) => is_array($entry)
? in_array($column, $entry)
: $entry === $column
);

// Handle full-text query depending on given type (string - single index; array - compound index)
if (! is_array($fullTextColumnTarget)) {
$query->orWhereFullText(
$builder->model->qualifyColumn($column),
$builder->query,
$this->getFullTextOptions($builder)
);

continue;
}

$query->orWhereFullText(
$builder->model->qualifyColumn($column),
Arr::map($fullTextColumnTarget, fn ($target) => $builder->model->qualifyColumn($target)),
$builder->query,
$this->getFullTextOptions($builder)
);

$fullTextColumnsChecked += $fullTextColumnTarget;
} else {
if ($canSearchPrimaryKey && $column === $builder->model->getScoutKeyName()) {
continue;
Expand Down