From bf38a7b1477cdbdbf90b38d892fcf777b9bae140 Mon Sep 17 00:00:00 2001 From: Hessam Date: Sun, 26 Apr 2020 22:08:44 +0430 Subject: [PATCH 1/6] excludes some records --- config/laravel-fulltext.php | 6 ++++++ src/Search.php | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config/laravel-fulltext.php b/config/laravel-fulltext.php index b17b816..0f99b9a 100644 --- a/config/laravel-fulltext.php +++ b/config/laravel-fulltext.php @@ -18,4 +18,10 @@ * Enable wildcard after words */ 'enable_wildcards' => true, + + /* + * Exclude some rows + */ + 'exclude_feature_enabled' => false, + 'exclude_records_column_name' => 'default_column' ]; diff --git a/src/Search.php b/src/Search.php index 9b9f9e1..d4859e3 100644 --- a/src/Search.php +++ b/src/Search.php @@ -56,10 +56,16 @@ public function searchQuery($search) '('.$titleWeight.' * (MATCH (indexed_title) AGAINST (?)) + '.$contentWeight.' * (MATCH (indexed_title, indexed_content) AGAINST (?)) ) DESC', - [$termsMatch, $termsMatch] - ) - ->limit(config('laravel-fulltext.limit-results')) - ->with('indexable'); + [$termsMatch, $termsMatch]) + ->limit(config('laravel-fulltext.limit-results')); + + if (config('laravel-fulltext.exclude_feature_enabled')){ + $query->with(array('indexable' => function($query){ + $query->where(config('laravel-fulltext.exclude_records_column_name'), '=', true); + })); + }else{ + $query->with('indexable'); + } return $query; } From 99e81419cbe3ca4d37d50fb5279de16fc1b7287e Mon Sep 17 00:00:00 2001 From: Hessam Date: Sun, 26 Apr 2020 22:54:56 +0430 Subject: [PATCH 2/6] updates readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 2748e23..98893a7 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,11 @@ Results on ``title`` or ``content`` are weighted in the results. Search result s Enable wildcard after words. So when searching for for example ``car`` it will also match ``carbon``. +### exclude_feature_enabled +This feature excludes some rows to be returned. Enable this when you have a toggle switch in your model which determines this record must be returned in search queries or not. By default this feature is disabled. +### exclude_records_column_name +The column name for that property (which acts as a toggle switch). This must match the exact column name at the table. + ## Change log Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. From facdb10a375e6e0d2512f1353ec9958fabd1b0fc Mon Sep 17 00:00:00 2001 From: Hessam Date: Tue, 28 Apr 2020 16:13:31 +0430 Subject: [PATCH 3/6] updates code style --- config/laravel-fulltext.php | 2 +- src/Search.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/laravel-fulltext.php b/config/laravel-fulltext.php index 0f99b9a..20203c8 100644 --- a/config/laravel-fulltext.php +++ b/config/laravel-fulltext.php @@ -23,5 +23,5 @@ * Exclude some rows */ 'exclude_feature_enabled' => false, - 'exclude_records_column_name' => 'default_column' + 'exclude_records_column_name' => 'default_column', ]; diff --git a/src/Search.php b/src/Search.php index d4859e3..3778388 100644 --- a/src/Search.php +++ b/src/Search.php @@ -59,11 +59,11 @@ public function searchQuery($search) [$termsMatch, $termsMatch]) ->limit(config('laravel-fulltext.limit-results')); - if (config('laravel-fulltext.exclude_feature_enabled')){ - $query->with(array('indexable' => function($query){ + if (config('laravel-fulltext.exclude_feature_enabled')) { + $query->with(['indexable' => function ($query) { $query->where(config('laravel-fulltext.exclude_records_column_name'), '=', true); - })); - }else{ + }]); + } else { $query->with('indexable'); } From 2a3308f0e80e5f79962d164ba896b54941e527c9 Mon Sep 17 00:00:00 2001 From: Hessam Date: Tue, 28 Apr 2020 16:46:32 +0430 Subject: [PATCH 4/6] updates readme file --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98893a7..b66c4f9 100644 --- a/README.md +++ b/README.md @@ -107,9 +107,9 @@ Results on ``title`` or ``content`` are weighted in the results. Search result s Enable wildcard after words. So when searching for for example ``car`` it will also match ``carbon``. ### exclude_feature_enabled -This feature excludes some rows to be returned. Enable this when you have a toggle switch in your model which determines this record must be returned in search queries or not. By default this feature is disabled. +This feature excludes some rows from being returned. Enable this when you have a flag in your model which determines whether this record must be returned in search queries or not. By default this feature is disabled. ### exclude_records_column_name -The column name for that property (which acts as a toggle switch). This must match the exact column name at the table. +The column name for that property (which acts as a flag). This must match the exact column name at the table. ## Change log From 9fe06c30dcfcc2f367c72599b7757eef39698635 Mon Sep 17 00:00:00 2001 From: Hessam Date: Thu, 30 Apr 2020 14:14:38 +0430 Subject: [PATCH 5/6] adds an example to readme file --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b66c4f9..474d7a1 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,16 @@ Results on ``title`` or ``content`` are weighted in the results. Search result s Enable wildcard after words. So when searching for for example ``car`` it will also match ``carbon``. ### exclude_feature_enabled -This feature excludes some rows from being returned. Enable this when you have a flag in your model which determines whether this record must be returned in search queries or not. By default this feature is disabled. + +This feature excludes some rows from being returned. Enable this when you have a flag in your model which determines whether this record must be returned in search queries or not. By default this feature is disabled. ### exclude_records_column_name + The column name for that property (which acts as a flag). This must match the exact column name at the table. +#### An example of using this feature + +Think about when you have a blog and then you add this search functionality to your blogging system to search through your blog posts. Sometimes you do not want some posts to be appeared in search result, for example when a post is not published yet. This feature helps you to do it. + ## Change log Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. From 30237a7b0b99600a3e492328eca01b5b604dc2fb Mon Sep 17 00:00:00 2001 From: Hessam Date: Thu, 30 Apr 2020 14:27:20 +0430 Subject: [PATCH 6/6] a little change --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 474d7a1..0397f37 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Enable wildcard after words. So when searching for for example ``car`` it will ### exclude_feature_enabled This feature excludes some rows from being returned. Enable this when you have a flag in your model which determines whether this record must be returned in search queries or not. By default this feature is disabled. + ### exclude_records_column_name The column name for that property (which acts as a flag). This must match the exact column name at the table.