From 78ae1c86e149f4f370e82967f43656dc568fdd5c Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Tue, 7 Nov 2023 20:18:15 +0100 Subject: [PATCH 1/3] Add scout search --- documentation.md | 1 + scout-search.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 scout-search.md diff --git a/documentation.md b/documentation.md index 14788f5..82ea2b4 100644 --- a/documentation.md +++ b/documentation.md @@ -53,6 +53,7 @@ - [Smart Search](/docs/{{package}}/{{version}}/smart-search) - [Starts With Search](/docs/{{package}}/{{version}}/starts-with-search) - [Relationships](/docs/{{package}}/{{version}}/relationships) + - [Scout Search](/docs/{{package}}/{{version}}/scout-search) - ## Sorting/Ordering - [Manual Order](/docs/{{package}}/{{version}}/manual-order) diff --git a/scout-search.md b/scout-search.md new file mode 100644 index 0000000..5df30bb --- /dev/null +++ b/scout-search.md @@ -0,0 +1,56 @@ +# Scout Search + +**Note:** This documentation is applicable from version 10.11.0 and upwards, where external search engines can be integrated with Laravel Scout, replacing the built-in search functionality. + +Scout Search provides a fallback mechanism, so the built-in search will be used if any issues occur with the external search engines (e.g., server problems or indexing problems). + +Supported drivers: Meilisearch, Algolia + + + +## Setup + +To start using Scout Search, you need to install and configure Laravel Scout with your preferred driver. + +Once Laravel Scout is set up, you can enable Scout Search in your `dataTable` function like this: + +```php +return (new EloquentDataTable($query)) + // Enable scout search for eloquent model + ->enableScoutSearch(Product::class) + + // Add filters to scout search + ->scoutFilter(function (string $keyword) { + return 'region IN ["Germany", "France"]'; // Meilisearch + // or + return 'region:Germany OR region:France'; // Algolia + }) + + // Add filters to default search + ->filter(function (QueryBuilder $query, bool $scout_searched) { + if (!$scout_searched) + { + // Filter already added for scout search + $query->whereIn('region', ['Germany', 'France']); + } + + // Stock is not indexed so it has to be filtered after the initial scout search + $query->where('stock', '>', 50); + }, true); +``` + + + +## Additional JS script + +To control the visibility of sort icons on the frontend table, you'll need an additional JavaScript script. This script hides the sort icons when Scout Search is successful (indicating fixed ordering by search relevance) and shows them again when the search keyword is removed. + +If you are using the `laravel-datatables-html` package, you can easily include the script in your `html` function: + +```php +return $this->builder() + ->setTableId('products-table') + ->addScript('datatables::scout'); +``` + +Alternatively, you can manually fetch and include the JavaScript script into your own code from this file: resources/views/scout.blade.php From fd97eaa9092d07197b79f80497ee0a0ddb02c109 Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Tue, 7 Nov 2023 20:28:54 +0100 Subject: [PATCH 2/3] Add html additional js scripts --- documentation.md | 1 + html-builder-additional-scripts.md | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 html-builder-additional-scripts.md diff --git a/documentation.md b/documentation.md index 82ea2b4..5397f22 100644 --- a/documentation.md +++ b/documentation.md @@ -93,6 +93,7 @@ - [Add Action](/docs/{{package}}/{{version}}/html-builder-action) - [Add Checkbox](/docs/{{package}}/{{version}}/html-builder-checkbox) - [Add Index](/docs/{{package}}/{{version}}/html-builder-index) + - [Additional Scripts](/docs/{{package}}/{{version}}/html-builder-additional-scripts) - [Github](https://github.com/yajra/laravel-datatables-html) - ## Buttons diff --git a/html-builder-additional-scripts.md b/html-builder-additional-scripts.md new file mode 100644 index 0000000..c8a4dc1 --- /dev/null +++ b/html-builder-additional-scripts.md @@ -0,0 +1,24 @@ +# Additional JavaScript Scripts + +## General Usage + +Starting with v10.10.0, you can easily add additional JavaScript scripts as blade views in your `html` function like this: + +```php +return $this->builder() + ->addScript('your.view.name'); +``` + +## Built-in Additional Scripts + +### Scout Search + +**View:** `datatables::scout` + +Control visibility of sort icons on the frontend table. Hide sort icons when Scout Search is successful (indicating fixed ordering by search relevance) and show them again when the search keyword is removed. + +### Batch Remove Optimization + +**View:** `datatables::functions.batch_remove` + +Delete all unnecessary information before sending `remove` requests (Editor), keeping only the `DT_RowId`. Otherwise, batch remove requests may fail because of server limits. From 1ae225603eed270821005d3ccdd58113cc5e402c Mon Sep 17 00:00:00 2001 From: Alpha Olomi Date: Wed, 6 Mar 2024 14:22:02 +0300 Subject: [PATCH 3/3] Add Article Community link --- community-links.md | 1 + 1 file changed, 1 insertion(+) diff --git a/community-links.md b/community-links.md index 601f8b5..2f28828 100644 --- a/community-links.md +++ b/community-links.md @@ -6,6 +6,7 @@ You may use the links below to further understand the Laravel Datatables. ## Articles - [Laravel Datatables Tutorial With Example](https://appdividend.com/2018/04/16/laravel-datatables-tutorial-with-example/) - [How to implement DataTables server-side in laravel](https://medium.com/justlaravel/how-to-implement-datatables-server-side-in-laravel-bcacf8472d70) +- [How to get started with DataTables in Laravel](https://dev.to/alphaolomi/how-to-get-started-with-datatables-in-laravel-9-5c39) ## Videos