Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Searchable | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| search | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| getSearchWeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| searchableAs | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Baril\Sqlout; |
| 4 | |
| 5 | use Laravel\Scout\Searchable as ScoutSearchable; |
| 6 | |
| 7 | trait Searchable |
| 8 | { |
| 9 | use ScoutSearchable; |
| 10 | |
| 11 | /** |
| 12 | * Perform a search against the model's indexed data. |
| 13 | * |
| 14 | * @param string $query |
| 15 | * @param \Closure $callback |
| 16 | * @return \Laravel\Scout\Builder |
| 17 | */ |
| 18 | public static function search($query = '', $callback = null) |
| 19 | { |
| 20 | return app(Builder::class, [ |
| 21 | 'model' => new static(), |
| 22 | 'query' => $query, |
| 23 | 'callback' => $callback, |
| 24 | 'softDelete' => static::usesSoftDelete() && config('scout.soft_delete', false), |
| 25 | ]); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get the weight of the specified field. |
| 30 | * |
| 31 | * @param string $field |
| 32 | * @return int |
| 33 | */ |
| 34 | public function getSearchWeight($field) |
| 35 | { |
| 36 | return $this->weights[$field] ?? 1; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the index name for the model when searching. |
| 41 | * |
| 42 | * @return string |
| 43 | */ |
| 44 | public function searchableAs() |
| 45 | { |
| 46 | return config( |
| 47 | 'scout.sqlout.table_name', |
| 48 | config('scout.prefix') . $this->getTable() . config('scout.suffix', '_index') |
| 49 | ); |
| 50 | } |
| 51 | } |