From 1cb8aac47b4aa149f15bec09d81c4b176dee6bae Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 14 Oct 2021 14:53:26 +0200 Subject: [PATCH] support for api key, added readme --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Provider.php | 15 +++++++--- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..cccc65a --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +![](https://extiverse.com/extension/blomstra/search/open-graph-image) + +Search replaces the native Flarum search functionality which relies on MySQL badly performing +fulltext search with one that is completely relying on the proven elasticsearch engine. + +## Features + +- Sync discussions to elastic search using your queue, unobtrusively for the user. +- Reduces search loading times to well below 400ms (local tests with 50.000 discussion **260ms**) +- Uses Flarum's group permissions and tags system. +- Compatible with Friends of Flarum Byōbu. + +## Premium + +Managed Flarum communities that we host on our platform ([blomstra](https://blomstra.net)) will have access to all premium extensions we publish without additional cost. + +Alternative you can see our plans on [extiverse](https://extiverse.com/extension/blomstra/search). After completing your order, check your active [subscriptions](https://extiverse.com/premium/subscriptions) and follow the provided instructions. Then install using: + +```bash +composer require blomstra/search:* +``` + +Enable the extension inside the admin area and continue below with the Set up. + +### Set up + +You will need a running Elasticsearch instance. Many providers offer these as a managed service, including +[Stack Hero](https://www.stackhero.io/en/services/Elasticsearch/benefits). + +Modify your `config.php` by adding an entry `elastic` like so: + +```php +return [ + 'elastic' => [ + 'endpoint' => 'https://somedomain:9200', + 'username' => '', + 'password' => '' + ] +]; +``` + +Or using an api token: + +```php +return [ + 'elastic' => [ + 'endpoint' => 'https://somedomain:9200', + 'api-id' => '', + 'api-key' => '' + ] +]; +``` + +Enable the extension in your admin area. Now to seed your existing discussions use the following command: + +``` +php flarum blomstra:search:documents:rebuild +``` + +All mutations to discussions are automatically added and removed from the elasticsearch index. + +### FAQ + +*I have another question.* +Reach out to us via https://helpdesk.blomstra.net. We will get back to you as soon as we can. If you have a running subscription please mention when you started your plan and/or which plan you are on. Always add sufficient information when reporting errors. We prefer errors being reported here, but understand that sometimes you can't. + +--- + +- Blomstra provides managed Flarum hosting. +- https://blomstra.net +- https://blomstra.community/t/ext-search diff --git a/src/Provider.php b/src/Provider.php index 1661bc3..8c2eb77 100644 --- a/src/Provider.php +++ b/src/Provider.php @@ -26,11 +26,18 @@ class Provider extends AbstractServiceProvider $elastic = Arr::get($config, 'elastic'); - return ClientBuilder::create() + $builder = ClientBuilder::create() ->setHosts([$elastic['endpoint']]) - ->setBasicAuthentication($elastic['username'], $elastic['password']) - ->setLogger($container->make(LoggerInterface::class)) - ->build(); + ->setLogger($container->make(LoggerInterface::class)); + + if ($elastic['api-key'] ?? false) { + $builder->setApiKey($elastic['api-id'], $elastic['api-key']); + } + if ($elastic['username'] ?? false) { + $builder->setBasicAuthentication($elastic['username'], $elastic['password']); + } + + return $builder->build(); }); }