Download the PHP package cyber-duck/silverstripe-searchly without Composer
On this page you can find all versions of the php package cyber-duck/silverstripe-searchly. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cyber-duck/silverstripe-searchly
More information about cyber-duck/silverstripe-searchly
Files in cyber-duck/silverstripe-searchly
Package silverstripe-searchly
Short Description Elastic Search integration for SilverStripe
License MIT
Homepage https://github.com/cyber-duck/silverstripe-searchly
Informations about the package silverstripe-searchly
SilverStripe Elastic Search
This package adds the ability to index DataObjects on any Elastic Search instance running on your local environment, on a server such as AWS, or an Elastic Search service such as Searchly.
Author: Andrew Mc Cormack
For SilverStripe 4.*
- Installation
- Configuration
- Setting Your Elastic Search Endpoint
- Setting DataObject Indexable Fields and Relations
- Performing Actions on a Search Index
- createIndex()
- deleteIndex()
- resetIndex()
- index()
- indexRecord()
- removeRecord()
- Creating an Index Task
- Performing a Search
- Configuring Your Search Query
- Getting Search Results
Installation
Add the following to your composer.json file and run /dev/build?flush=all
Configuration
Refer to _config/searchly.yml
for configuration options.
Setting Your Elastic Search Endpoint
Add a SEARCHLY_BASE_URI var to your .env file with any valid ES endpoint (AWS, searchly etc)
Or for a local docker ES instance or similar
Setting DataObject Indexable Fields and Relations
Models and their relations can be indexed together as one searchable object. To index fields and their relations you can use searchable_* config arrays on your DataObject.
In the example below the relations Tags & ContentBlocks would need their own searchable_* config. When indexing, these relationships will be traversed and a nested objects created.
Performing Actions on a Search Index
Creating a search index instance allow you access to functions to change and manipulate a search index such as creating a new one, adding / removing records etc
createIndex($mappings = [], $settings = [])
Calling this method on your search index instance will build an ES endpoint index. For full configuration for mappings and settings please see the Elastic Search documentation.
deleteIndex()
This method will completely remove the search index from your ES endpoint
resetIndex($mappings = [], $settings = [])
This method will call deleteIndex() and then call createIndex(). Make sure to pass your mappings and settings configuration as you would for createIndex();
index(array $filters = [])
This method will push all the models to the ES endpoint index you specified when creating your search index instance.
In the example below calling index will traverse through all Page and File models, create a JSON representation of them and push them to the ES endpoint index.
You can also apply filters in case you wish to exclude certain model from the index.
You can also see all the data sent to the ES endpoint index by calling index() then getRecords(). This will return an array of JSON objects.
indexRecord(DataObject $record)
Adds a single data object to the ES endpoint index
removeRecord(DataObject $record)
Removes a single data object from the ES endpoint index
Creating an Index Task
The easiest way to create your indexes is to create a SilverStripe task and run it to create / rebuild all your indexes
If you run into PHP time outs with indexing large numbers of models, you can try to increase the execution time
Performing a Search
To perform a search query create a new SearchQuery instance and inject the search term and index name into the constructor.
Configuring Your Search Query
You can control the amount of results returned. Useful for very large data sets.
You can also control AND / OR matching
There is also a custom method for setting analyze_wildcard config to true / false
Or you can build your own highly complex configurations for any situation.
Getting Search Results
To return an array of matched model IDs you can call getIDs()
To return an array of matched objects you can call getHits()
Highlights / matched text can also be returns by calling setHighlight() on the SearchQuery instance and calling getHighlights()
To return the full ES endpoint response object you can call getResponse() on your query object. Useful for debugging.