Skip to content

Commit c9d5845

Browse files
Merge pull request #34 from ginkelsoft-development/develop
Dev into Main
2 parents 4bc35a3 + ad54caa commit c9d5845

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Traits/HasEncryptedSearchIndex.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,16 @@ public function scopeEncryptedPrefix(Builder $query, string $field, string $term
349349
return $query->whereIn($this->getQualifiedKeyName(), $modelIds);
350350
}
351351

352-
// Fallback to database
352+
// Fallback to database with relevance sorting
353+
// Sort by field length (shorter matches = more relevant)
353354
return $query->whereIn($this->getQualifiedKeyName(), function ($sub) use ($field, $tokens) {
354355
$sub->select('model_id')
355356
->from('encrypted_search_index')
356357
->where('model_type', static::class)
357358
->where('field', $field)
358359
->where('type', 'prefix')
359360
->whereIn('token', $tokens);
360-
});
361+
})->orderByRaw("LENGTH({$field}) ASC");
361362
}
362363

363364
/**
@@ -408,6 +409,8 @@ public function scopeEncryptedPrefixMulti(Builder $query, array $fields, string
408409
}
409410

410411
// Fallback to database - use OR logic for multiple fields
412+
// Note: Multi-field searches don't have relevance sorting due to database compatibility
413+
// Use single-field searches for relevance-sorted results
411414
return $query->whereIn($this->getQualifiedKeyName(), function ($sub) use ($fields, $tokens) {
412415
$sub->select('model_id')
413416
->from('encrypted_search_index')

0 commit comments

Comments
 (0)