ZincSearch is a Statamic addon to speed up your listing views in the control by using the power of ZincSearch.
This addon makes your control panel listings go super-dooper-fast.
Ensure you have a working ZincSearch installation.
Run the following command from your project root:
composer require thoughtco/zinc-search
Add the zincsearch
driver to the drivers array in config/statamic/search.php
:
'zincsearch' => [
'credentials' => [
'url' => env('ZINCSEARCH_URL', ''),
'username' => env('ZINCSEARCH_USERNAME', ''),
'password' => env('ZINCSEARCH_PASSWORD', ''),
],
],
Add the variables to your .env
file for ZINCSEARCH_URL
, ZINCSEARCH_USERNAME
and ZINCSEARCH_PASSWORD
.
Set up a search index for the collection e.g.
'pages' => [
'driver' => 'zincsearch',
'searchables' => ['collection:pages'],
'fields' => ['id', 'title', 'url', 'content', 'status'],
'searchable_fields' => ['title, 'slug'],
'settings' => [],
],
Then apply this to your collection YAML definition with a key of search_index e.g.
title: Pages
revisions: false
title_format: null
sort_by: title
sort_dir: asc
preview_targets:
-
label: Entry
url: '{permalink}'
structure:
root: true
search_index: pages
To make use of this use the speed of this search in your front end, use the search_index
tag instead of collection
.
e.g.
{{ search:results index="pages" supplement_data="false" for="*" as="results" limit="10" offset="0" paginate="10" }}
{{ if no_results }}
No results
{{ else }}
{{ results }}
<p>{{ id }} - {{ title }}</p>
{{ /results }}
{{ /if }}
{{ /search:results }}