werkbot / werkbot-search
Provides search functionality with TNTSearch
Installs: 1 281
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- php: ^8.0 || ^8.1
- ext-sqlite3: *
- silverstripe/cms: ^4 || ^5
- silverstripe/framework: ^4 || ^5
- symbiote/silverstripe-queuedjobs: ^4.12 || ^5.1
- teamtnt/tntsearch: v4.2.1
Requires (Dev)
- code-lts/doctum: ^5.5
This package is auto-updated.
Last update: 2024-10-24 15:12:56 UTC
README
A silverstripe search module that utilizes TNTSearch to index content.
Installation
composer require werkbot/werkbot-search
Requirements
Setup
Add the following extensions to Page
Page::add_extension(SearchableExtension::class); PageController::add_extension(SearchControllerExtension::class);
You will need to run dev/build
Define getIndexQuery on Page
The Page::class
will need to have a function getIndexQuery
defined. Here is an example for Page:
/** * getIndexQuery * This query is used when building the index * * @return string|boolean - FALSE if not set */ public function getIndexQuery() { return "SELECT concat(\"Page_\", SiteTree.ID) AS ID, SiteTree.ClassName, SiteTree.Title, SiteTree.Content FROM Page LEFT JOIN SiteTree ON SiteTree.ID = Page.ID WHERE SiteTree.ShowInSearch = '1'" AND SiteTree.Content IS NOT NULL; }
This is a simple query that is used by the indexer to index your content.
This function can be customized however you like and also can be added to DataObjects.
Data Extensions
Note that if the getIndexQuery
method is defined in a DataExtension, the SearchableExtension
must be added before the extension that adds the method. Otherwise the method will return the default: false.
SearchableDataObject::add_extension(SearchableExtension::class); // MUST BE APPLIED FIRST for getIndexQuery to return SQL Query string. SearchableDataObject::add_extension(SearchableDataObjectExtension::class); // Defines getIndexQuery SQL Query string.
External Libraries
By default, the templates used here use classes provided by external css libraries. We suggest installing both for the best experience:
- Werkbot Framewerk (CSS Libarary)
- Font Awesome 6 (Icon classes)