https://github.com/firesphere/silverstripe-elastic
Elastic Enterprise and Elastic Search integration with the same/similar api as the Solr integration
https://github.com/firesphere/silverstripe-elastic
elastic hacktoberfest hacktoberfest2023 search silverstripe
Last synced: 6 months ago
JSON representation
Elastic Enterprise and Elastic Search integration with the same/similar api as the Solr integration
- Host: GitHub
- URL: https://github.com/firesphere/silverstripe-elastic
- Owner: Firesphere
- License: bsd-3-clause
- Created: 2023-09-28T22:13:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-23T20:54:03.000Z (almost 3 years ago)
- Last Synced: 2025-04-06T11:50:13.199Z (over 1 year ago)
- Topics: elastic, hacktoberfest, hacktoberfest2023, search, silverstripe
- Language: PHP
- Homepage:
- Size: 187 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/Firesphere/silverstripe-elastic/actions/workflows/unittests.yml)
[](https://codecov.io/gh/Firesphere/silverstripe-elastic)
[](https://codeclimate.com/github/Firesphere/silverstripe-elastic/maintainability)
[](https://scrutinizer-ci.com/g/Firesphere/silverstripe-elastic/?branch=main)
# Modern Silverstripe Elastic search
## Installation
`composer require firesphere/elastic`
### Requirements
- PHP8+
- Elasticsearch 8.10+
- Silverstripe Framework 4 || 5
## Elastic search with Silverstripe
This module provides an API similar to the [Solr Search](https://firesphere.github.io/solr-search) module.
### Basic search index
- Create an API-index in your ElasticSearch instance
- If you have Elastic Enterprise, this is under Search => API
- Create an API key
- You can use a username/password, but API key is recommended
### Configuring the service
Configuration is done in YML:
```yaml
---
Name: MyElastic
---
Firesphere\ElasticSearch\Services\ElasticCoreService:
config:
endpoint:
- host: "https://my-elasticinstance.elastic-cloud.com"
apiKey: "mybase64apikeyhere==="
username: "Elastic"
password: "mysupersecretpassword"
port: 443
```
Take special note of the port. When using your own Elastic instance, this might be the standard port 9200.
On Elastic Cloud, it's all routed through a reverse proxy on port 443 (https).
*NOTE*
It's obviously never a great idea to use api keys or passwords in YML, but that's okay,
to configure it from environment:
```dotenv
ELASTIC_ENDPOINT=host.example.com
ELASTIC_USERNAME=user@example.com
ELASTIC_PASSWORD=examplepassword
ELASTIC_API_KEY=mybase64apikeyhere===
ELASTIC_PORT=443
ELASTIC_PROTOCOL=https
```
And in your YML:
```yaml
---
Name: MyElastic
---
Firesphere\ElasticSearch\Services\ElasticCoreService:
config:
endpoint: ENVIRONMENT
```
### Creating an index
An index has two parts, the class and the configuration.
The most basic class would by something like the following:
```php
getRequest()->getVars();
if (isset($query['query'])) {
$baseQuery = new ElasticQuery();
// Add the term
$baseQuery->addTerm($query['query']);
// Ensure to start at 0
$start = isset($query['start']) ? $query['start'] : 0;
$baseQuery->setStart($start);
// Get the index
$index = new ElasticProjectIndex();
// And do the search
$this->Results = $index->doSearch($baseQuery);
}
return $this;
}
}
```
## Permissions
As with the Solr search, all documents are indexed with a `ViewStatus` field.
This field determines who can see the results. At search runtime, the value is calculated based on the current user
and as such passed in as an extra, required, filter.
### Further functionality
#### Done(~ish)
- [x] Basic filtering
- [x] Pagination
- [x] Actually, you know... search
- [x] Highlighting~ish
- [x] Synonyms
- [x] Group-access filtering (e.g. all, administrators, specific groups, from access setting in the CMS)
- [x] Boosting
- [x] Faceting
- [x] Spellchecking
- [x] Unit tests and integration tests
#### On the to-do list is:
- [ ] Work out the filtering better
- [ ] File content searching
- [ ] Submodules for
- [ ] Member level permissions
- [ ] Subsites
- [ ] Fluent
# Cow?
Cow!
```
/( ,,,,, )\
_\,;;;;;;;,/_
.-"; ;;;;;;;;; ;"-.
'.__/`_ / \ _`\__.'
| (')| |(') |
| .--' '--. |
|/ o o \|
| |
/ \ _..=.._ / \
/:. '._____.' \
;::' / \ .;
| _|_ _|_ ::|
.-| '==o==' '|-.
/ | . / \ | \
| | ::| | | .|
| ( ') (. )::|
|: | |; U U ;|:: | `|
|' | | \ U U / |' | |
##V| |_/`"""`\_| |V##
##V## ##V##
```
# Sponsors
// @todo Firesphere needs to get some sponsor logos (And maybe some sponsors?)