Download the PHP package pixelpoems/silverstripe-search without Composer
On this page you can find all versions of the php package pixelpoems/silverstripe-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pixelpoems/silverstripe-search
More information about pixelpoems/silverstripe-search
Files in pixelpoems/silverstripe-search
Package silverstripe-search
Short Description Silverstripe Search-Module including loading search results js api requests.
License BSD-3-Clause
Informations about the package silverstripe-search
Silverstripe Search Module
This module provides a silverstripe search using ajax and configurable indexing. You can use it in combination with Silverstripe Elemental and Fluent. For Elemental and Fluent configuration check the specified documentation below.
- Requirements
- Installation
- Configuration
- Populate Task
- Overwrite Template Files
- Inline Search
- Enable Search on DataObjects
- Config to enable Elemental
- Config to enable Fluent
- Available Config Variables
Requirements
- Silverstripe CMS >=4.0
- Silverstripe Framework >=4.0
- Versioned Admin >=1.0
Installation
This module includes
Populate Search Task
- Task to create or update the search indexSearch Page
- Separate Search PageInline Search
- Template Include
Configuration
Without any special configurations all pages and subclasses of page, which have the "Show in Search" Checkbox checked,
will be indexed. For indexing you have to run the PopulateSearch
Task (More Details: Populate Task).
Following variables can be used to configure your search index:
Those keys are only for separating data within the index (more or less for your own structure - this keys won't be
displayed in the search result!). The search prioritises the content based on the keys - title
has the first priority
in this case and is therefore also displayed first in the result.
By default, your index file is named index.json
and will be placed at /search/
within your project root directory.
Add /search
to your .gitignore
to prevent index files from being pushed to your git repository.
To Update or set the index keys based on the Class you can extend the Class and use the following method to set the
values. If you set extra values here, they won't get noticed by the js logic. Only the predefined keys will be
recognised. $data
will contain all preconfigured keys.
To update the data without extension e.g. on a new PageType you can add the following function to your new Page Type with your custom list, which should be indexed:
To add multiple values e.g. Tags or something similar you can do like this:
You can use the SearchService::escapeHTML($string)
function to escape your content before adding it to the index.
Populate Task
To create or update the search index use the "Search Populate" Task:
This Task will create based on your configuration an index.json
and an index-elemental.json
(if elemental is
enabled) or locale.json
and locale-elemental.json
(if fluent is enabled).
You can extend the search population and add additional Data like that:
Your Data will be saved within index.json
or locale.json
ATTENTION: Make sure your DataObject has a Link function, so that it can be linked within the search result.
If you want to populate custom data without an DataObject you can add a "link" key to your custom array:
This will generate a custom Array Data with your context - in the ideal case the array contains the keys id
, link
and your defined index_keys
.
Overwrite Template Files
To overwrite the default search templates you can create a Pixelpoems/Search
folder within your project templates.
Pixelpoems/Search/Ajax/SearchResultList.ss
for the rendered Search result.Pixelpoems/Search/Includes/InlineSearch.ss
for inline Search output.Pixelpoems/Search/Pages/Layout/SearchPage.ss
for your custom Search Page.
ATTENTION: If you overwrite the templates, make sure that the required js files are included within the templates or
will be included via a Controller and the CSS Classes and IDs are there as well. Make sure that the inline search is
wrapped within an element with the classes search-holder inline-search-holder
and within a search-holder
class on
the search page template!
If you need additional Variables within your Ajax Search Result List Template Pixelpoems/Search/Ajax/SearchResultList.ss
you
can extend the Pixelpoems/Search/Controllers/SearchController
and update the data with the following hook:
All the Variables, that are added here can be accessed in your custom Ajax/SerachList.ss
.
Inline Search
This module includes an inline search. The listing within the inline search will display up to ten search results and a "See more..." item which navigates to the search page which will display all search results in a list.
Include the InlineSearch Template within your template:
Enable Search on DataObjects
If you want to add data of an DataObject you can add text like described in the Configuration section indexing a page or an element.
Here you can add e.g. the title
and content
within the index process of a single page along to all other objects.
Config to enable Elemental
To enable indexing elemental add the following to your configuration yml:
Furthermore, you can use exclude_elements_from_index
to prevent specific Element Classes from being indexed:
And add the SearchIndexExtension
to the Base Element Model:
After adding the extension you can use the updateSearchIndexData
hook to specify your index data.
Enable Virtual Element Indexing
If you use Virtual Elements from DNADesign and you want to index the Connected Data for this element you can add the following Extension to the base "ElementVirtual" Class, this will handle the default indexing with the "Linked Element" Data.
Config to enable Fluent
To enable fluent within the index and search process add the following to your configuration yml:
If you enabled fluent threw the config the Populate Search Task
will create an index file for every locale. To prevent
a locale from beeing indexed you can add the Locale title within the static variable exclude_locale_from_index
like
this:
By default, your index files are named {locale}.json
, e.g. de_AT.json
.
Modify Search Result
There are multiple hooks to modify the search result before sending the generated list to the template:
Add an extension to SearchService:
Modify List BEFORE limiting result
Use the hook updateSearchResultBeforeLimit
for instance to filter the results on a specific Mulitsite if you use e.g. https://github.com/symbiote/silverstripe-multisites
The limitation of the list (for Inline Search) will be added after the hook.
Modify List AFTER limiting result
Use the hook updateSearchResultAfterLimit
for instance to filter the results after the limitation has been added to the list.
This will hook will only be called on a request that is made by the inline search!
If you want to modify the result after limitation for inline search AND on the Search page use the hook updateSearchResult
:
Available Config Variables
Every config can be made via the Pixelpoems\Search\Services\SearchConfig
class:
Name | Default |
---|---|
enable_default_style | true |
index_keys | ['title'] |
enable_fluent | false |
exclude_locale_from_index | [] |
enable_elemental | false |
exclude_elements_from_index | [] |
max_results_inline | 10 |
Reporting Issues
Please create an issue for any bugs you've found, or features you're missing.
Credits
Search and Close icons from Feather Icons - https://feathericons.com/
All versions of silverstripe-search with dependencies
silverstripe/cms Version ^4
silverstripe/framework Version ^4.0
silverstripe/vendor-plugin Version ^1.0