Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SearchDataRepository
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 searchShortcuts
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 searchTemplates
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Repositories;
4
5use App\Http\Models\Shortcut;
6use App\Http\Models\Template;
7use App\Http\Repositories\interfaces\ISearchDataRepository;
8use Illuminate\Support\Collection;
9
10/**
11 * Repository for search data queries.
12 *
13 * Handles database access for searching shortcuts and templates.
14 * All queries use Eloquent query builder for database-agnostic compatibility.
15 */
16class SearchDataRepository implements ISearchDataRepository
17{
18    /**
19     * {@inheritDoc}
20     */
21    public function searchShortcuts(string $query, int $limit = 50): Collection
22    {
23        $regex = new \MongoDB\BSON\Regex($query, 'i'); // 'i' makes it case-insensitive
24
25        return Shortcut::with('category')
26            ->where(function ($queryBuilder) use ($regex) {
27                $queryBuilder->where('title', 'regex', $regex)
28                    ->orWhere('text', 'regex', $regex)
29                    ->orWhere('html', 'regex', $regex)
30                    ->orWhere('shortcut', 'regex', $regex)
31                    ->orWhere('first_line', 'regex', $regex);
32            })
33            ->limit($limit)
34            ->get();
35    }
36
37    /**
38     * {@inheritDoc}
39     */
40    public function searchTemplates(string $query, int $limit = 50): Collection
41    {
42        $regex = new \MongoDB\BSON\Regex($query, 'i'); // 'i' makes it case-insensitive
43
44        return Template::with('category')
45            ->where(function ($queryBuilder) use ($regex) {
46                $queryBuilder->where('title', 'regex', $regex)
47                    ->orWhere('text', 'regex', $regex)
48                    ->orWhere('html', 'regex', $regex)
49                    ->orWhere('shortcut', 'regex', $regex)
50                    ->orWhere('first_line', 'regex', $regex);
51            })
52            ->limit($limit)
53            ->get();
54    }
55}