From 6dcc3e5d802fc0af18bdffcdd8a01c6904a5e119 Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Sun, 30 Apr 2017 16:29:36 +1000 Subject: [PATCH] Addition of new AmbiSearchDriver to allow more intuitive text search --- config/searchy.php | 4 +++ src/Matchers/DeterminerMatcher.php | 33 +++++++++++++++++++ src/Matchers/InsideStartOfWordsMatcher.php | 14 ++++++++ src/Matchers/PositionInSearchMatcher.php | 19 +++++++++++ src/SearchDrivers/AmbiSearchDriver.php | 15 +++++++++ src/SearchDrivers/FuzzySearchDriver.php | 5 +-- .../FuzzySearchUnicodeDriver.php | 5 +-- src/SearchDrivers/SimpleSearchDriver.php | 3 -- 8 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 src/Matchers/DeterminerMatcher.php create mode 100644 src/Matchers/InsideStartOfWordsMatcher.php create mode 100644 src/Matchers/PositionInSearchMatcher.php create mode 100644 src/SearchDrivers/AmbiSearchDriver.php diff --git a/config/searchy.php b/config/searchy.php index 06fceac..9c72eb3 100755 --- a/config/searchy.php +++ b/config/searchy.php @@ -12,6 +12,10 @@ 'class' => 'TomLingham\Searchy\SearchDrivers\FuzzySearchDriver', ], + 'ambi' => [ + 'class' => 'TomLingham\Searchy\SearchDrivers\AmbiSearchDriver', + ], + 'ufuzzy' => [ 'class' => 'TomLingham\Searchy\SearchDrivers\FuzzySearchUnicodeDriver', ], diff --git a/src/Matchers/DeterminerMatcher.php b/src/Matchers/DeterminerMatcher.php new file mode 100644 index 0000000..ab0440d --- /dev/null +++ b/src/Matchers/DeterminerMatcher.php @@ -0,0 +1,33 @@ +multiplier, 0)"; + }, $determiners); + + $query = implode($queries, ' + '); + + return $query; + } +} diff --git a/src/Matchers/InsideStartOfWordsMatcher.php b/src/Matchers/InsideStartOfWordsMatcher.php new file mode 100644 index 0000000..7162d68 --- /dev/null +++ b/src/Matchers/InsideStartOfWordsMatcher.php @@ -0,0 +1,14 @@ +multiplier - ROUND( + (POSITION('$searchString' IN $column) - 1) / CHAR_LENGTH($column) * $this->multiplier + ) + )"; + + return $query; + } +} diff --git a/src/SearchDrivers/AmbiSearchDriver.php b/src/SearchDrivers/AmbiSearchDriver.php new file mode 100644 index 0000000..e422fc3 --- /dev/null +++ b/src/SearchDrivers/AmbiSearchDriver.php @@ -0,0 +1,15 @@ + 150, + \TomLingham\Searchy\Matchers\DeterminerMatcher::class => 110, + \TomLingham\Searchy\Matchers\PositionInSearchMatcher::class => 100, + \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 90, + \TomLingham\Searchy\Matchers\InsideStartOfWordsMatcher::class => 50, + \TomLingham\Searchy\Matchers\StartOfWordsMatcher::class => 35, + ]; +} diff --git a/src/SearchDrivers/FuzzySearchDriver.php b/src/SearchDrivers/FuzzySearchDriver.php index 16c14f2..7916211 100755 --- a/src/SearchDrivers/FuzzySearchDriver.php +++ b/src/SearchDrivers/FuzzySearchDriver.php @@ -4,9 +4,6 @@ class FuzzySearchDriver extends BaseSearchDriver { - /** - * @var array - */ protected $matchers = [ \TomLingham\Searchy\Matchers\ExactMatcher::class => 100, \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 50, @@ -16,5 +13,5 @@ class FuzzySearchDriver extends BaseSearchDriver \TomLingham\Searchy\Matchers\StudlyCaseMatcher::class => 32, \TomLingham\Searchy\Matchers\InStringMatcher::class => 30, \TomLingham\Searchy\Matchers\TimesInStringMatcher::class => 8, -]; + ]; } diff --git a/src/SearchDrivers/FuzzySearchUnicodeDriver.php b/src/SearchDrivers/FuzzySearchUnicodeDriver.php index d3a3b41..7cf6cb4 100644 --- a/src/SearchDrivers/FuzzySearchUnicodeDriver.php +++ b/src/SearchDrivers/FuzzySearchUnicodeDriver.php @@ -4,9 +4,6 @@ class FuzzySearchUnicodeDriver extends BaseSearchDriver { - /** - * @var array - */ protected $matchers = [ \TomLingham\Searchy\Matchers\ExactMatcher::class => 100, \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 50, @@ -16,5 +13,5 @@ class FuzzySearchUnicodeDriver extends BaseSearchDriver \TomLingham\Searchy\Matchers\StudlyCaseUnicodeMatcher::class => 32, \TomLingham\Searchy\Matchers\InStringMatcher::class => 30, \TomLingham\Searchy\Matchers\TimesInStringMatcher::class => 8, - ]; + ]; } diff --git a/src/SearchDrivers/SimpleSearchDriver.php b/src/SearchDrivers/SimpleSearchDriver.php index b18770c..00417ff 100755 --- a/src/SearchDrivers/SimpleSearchDriver.php +++ b/src/SearchDrivers/SimpleSearchDriver.php @@ -4,9 +4,6 @@ class SimpleSearchDriver extends BaseSearchDriver { - /** - * @var array - */ protected $matchers = [ \TomLingham\Searchy\Matchers\ExactMatcher::class => 100, \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 50,