Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit d3eba50

Browse files
committed
refactoring
1 parent 5b15fcf commit d3eba50

8 files changed

Lines changed: 30 additions & 71 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,21 @@ User::whereFuzzy('name', 'jd')
8989
->orderBy('relevance_email', 'desc')
9090
->first();
9191
```
92-
### Setting Minimum Match Threshold
92+
### Applying a minimum threshold
9393

94-
When using quest an overall score will be assigned to each row `_fuzzy_relevance_` with a range of 0-100.
94+
When using Quest, an overall score will be assigned to each record within the `_fuzzy_relevance_` column. This score is represented as an `integer` between 0 and 100.
9595

96-
You can enforce a minimum match standard and limit results returned by using `->atLeastFuzzy()`
96+
You can enforce a minimum score to restrict the results by using the `withMinimumRelevance()` method. Setting a higher score will return fewer, but likely more-relevant results.
9797

9898
```php
99+
// Before
99100
User::whereFuzzy('name', 'jd')
100-
->atLeastFuzzy(70)
101+
->having('_fuzzy_relevance_', '>', 70)
101102
->first();
102103

103-
// Equivalent to:
104-
104+
// After
105105
User::whereFuzzy('name', 'jd')
106-
->having('_fuzzy_relevance_', '>', 70)
106+
->withMinimumRelevance(70)
107107
->first();
108108
```
109109

resources/build.svg

Lines changed: 0 additions & 20 deletions
This file was deleted.

resources/coverage.svg

Lines changed: 0 additions & 20 deletions
This file was deleted.

resources/version.svg

Lines changed: 2 additions & 2 deletions
Loading

src/Macros/AtLeast.php

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Quest\Macros;
4+
5+
use Illuminate\Database\Query\Builder;
6+
7+
class withMinimumRelevance
8+
{
9+
/**
10+
* Construct a fuzzy search expression.
11+
*
12+
*/
13+
public static function make(Builder $builder, int $score) : Builder
14+
{
15+
return $builder->having('_fuzzy_relevance_', '>=', $score);
16+
}
17+
}

src/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Quest;
44

55
use Closure;
6-
use Quest\Macros\AtLeast;
76
use Quest\Macros\WhereFuzzy;
87
use Quest\Macros\OrderByFuzzy;
98
use Illuminate\Database\Query\Builder;
9+
use Quest\Macros\withMinimumRelevance;
1010
use Illuminate\Support\ServiceProvider as Provider;
1111

1212
class ServiceProvider extends Provider
@@ -42,6 +42,6 @@ public function boot(): void
4242
return WhereFuzzy::makeOr($this, $field, $value);
4343
});
4444

45-
Builder::macro('atLeastFuzzy', fn($minScore) => AtLeast::make($this, $minScore));
45+
Builder::macro('withMinimumRelevance', fn($score) => withMinimumRelevance::make($this, $score));
4646
}
4747
}

tests/PackageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ public function it_can_perform_an_eloquent_fuzzy_and_search_with_fuzzy_order()
179179
public function it_can_limit_minimum_score()
180180
{
181181
$results = User::whereFuzzy('name', 'joh Do')
182-
->atLeastFuzzy(65)
182+
->withMinimumRelevance(65)
183183
->get();
184184

185185
$this->assertEquals('John Doe', $results->first()->name);
186186

187187
$results = User::whereFuzzy('name', 'joh Do')
188-
->atLeastFuzzy(70)
188+
->withMinimumRelevance(70)
189189
->get();
190190

191191
$this->assertCount(0, $results);

0 commit comments

Comments
 (0)