Download the PHP package clarkwinkelmann/flarum-ext-scout without Composer

On this page you can find all versions of the php package clarkwinkelmann/flarum-ext-scout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package flarum-ext-scout

Scout Search for Flarum

MIT license Latest Stable Version Total Downloads Donate

Integrates Laravel Scout with Flarum discussion and user search.

Just like with Laravel, the data is automatically synced with the search index every time a model is updated in Flarum. You only need to manually import data when you enable the extension (see commands below).

The external search driver is used server-side to filter down the MySQL results, so it should still be compatible with every other extension and search gambits.

Algolia and Meilisearch drivers are included in the extension. TNTSearch is supported but requires the manual installation of an additional package. The Scout database and collection drivers cannot be used (they would be worst than Flarum's built-in database search).

See below for the specific requirements and configuration of each driver.

While only discussions and users are searchable in Flarum, this implementation also uses a posts search index which is merged with discussion search results in a similar way to the Flarum native search. The discussion result sort currently prioritize best post matching because I have not found a way to merge the match score of discussions and posts indices.

All CLI commands from Scout are available, with an additional special "import all" command:

Algolia

The Algolia driver requires an account on the eponymous cloud service.

Meilisearch

The Meilisearch driver requires a running Meilisearch server instance. The server can be hosted anywhere as long as it can be reached over the network. By default, the extension attempts to connect to a server at 127.0.0.1:7700.

If you are not running the latest Meilisearch version you might need to explicitly install an older version of the SDK. Likewise, if you are regularly running composer update on all your dependencies, you should also add an explicit requirement for the Meilisearch SDK in your composer.json because the extension requires * which might jump to a newer Meilisearch SDK version as soon as it comes out.

To install and lock the current latest version:

composer require meilisearch/meilisearch-php

Unfortunately Meilisearch doesn't seem to advertise which specific version of the Composer package is compatible with each server version. You can find the list of releases at https://packagist.org/packages/meilisearch/meilisearch-php

Once you know which version you need, you can lock it, for example to install the older 0.23:

composer require meilisearch/meilisearch-php:"0.23.*"

The only settings for Meilisearch are Host and Key. Everything else is configured in the Meilisearch server itself.

Even if you don't configure the Default Results Limit value and use Meilisearch, the extension will automatically set it to 200 for you because the default for Meilisearch (20) is extremely low and result in only 2 pages of results at best.

TNTSearch

The TNTSearch library requires the sqlite PHP extension, therefore it's not included by default with Scout.

To install it, make sure you have the sqlite PHP extension enabled for both command line and webserver and run:

composer require teamtnt/laravel-scout-tntsearch-driver

TNTSearch uses local sqlite databases for each index. The databases are stored in <flarum>/storage/tntsearch which must be writable.

The following settings are exposed. What each setting does isn't entirely clear, TNTSearch own documentation doesn't offer much guidance.

As You Type and Search Boolean are hard-coded to enabled, though they don't seem to work as described in TNTSearch documentation.

Installation

This extension is still experimental. Please test on a staging server first. I have not tested Algolia personally yet, but from feedback it seems to be working.

composer require clarkwinkelmann/flarum-ext-scout

Supported extensions and fields

This list is not exhaustive. If you added support for Scout in your extension, let me know so I can update this list.

Discussions

When searching for discussions via Flarum's search feature, the fields for Posts are also queried.

Posts

Users

Email is intentionally not searchable because there's currently no mechanism that would prevent regular users from using that feature to leak email.

Formulaire

Forms and Submissions are optionally indexed via Scout. See Formulaire documentation for details.

Developers

Extend the search index of existing models

Use the extender to register your attributes, similar to extending Flarum's serializers.

Additionally, you should register an event listener that's triggered when your attribute value changes.

If registering an event listener is not an option, you can also call the update code manually after you change the value:

If you are modifying a Flarum model outside the original store/edit/delete handlers, don't forget to trigger Flarum events (like Started and Deleted for discussions) so that Scout can sync your changes.

Add your own search engine

Any search engine extending Laravel\Scout\Engines\Engine that works with Laravel Scout should be compatible with this Flarum implementation.

There's currently no extender to connect a new engine from an external package. You will likely need to override the EngineManager by forking this extension or by using a container binding.

Make your own models searchable

Due to the constraints of making Scout optional and extendable, the Scout API for model configuration and retrieval contains a number of changes compared to Laravel. Where possible, similar names have been kept for the concepts, even if they now happen through extenders or new global methods.

Because there's no way to add the Searchable trait to Flarum (or extensions) Eloquent models without making Scout a requirement, the trait is not used. Do not add the Searchable trait to your Eloquent models, even if you have the ability to edit the model source code!

This documentation mentions 2 kind of models, "real" models are the Eloquent models from Flarum or extensions that don't have the Searchable trait, like Flarum\User\User. "wrapped" models is a special feature of this extension where a "real" model is wrapped into a special model that gives it the Searchable abilities. Generally, "wrapped" models will be transparently used under the hood by this extension without any special action required by the programmers. If you wish to manually obtain a "wrapped" model to call specific Scout methods on it, you can wrap it with new ScoutModelWrapper($model).

The built-in Scout model observer is not used, instead Flarum events are used to trigger index updates.

Summary of the differences with Laravel:

The Support/Eloquent collection methods work with arrays of either real or wrapped models:

The query builder methods/scopes work on real models:

The scout methods aren't available on real models but all the useful methods have alternative means to be called:

The Scout:: static object is not used:

A new object not part of the original Scout is offered for static methods:

To use the scout to filter results in your code, I recommend ignoring every builder/model methods and directly retrieve the matching IDs through the Scout Builder instance.

You can then use that array of matching IDs to modify a Flarum searcher (see this extension source code for the post/user searchers), filterer, or a manual query.

Caution: the array of IDs will contain deleted and private content as well. Make sure to always use Flarum's whereVisibleTo() somewhere in the query.

To preserve the search result order, one option is to use the FIELD() SQL method. You could also re-sort the results in PHP after retrieving them from the database if you are not paginating.

Support

This extension is under minimal maintenance.

It was developed for a client and released as open-source for the benefit of the community. I might publish simple bugfixes or compatibility updates for free.

You can contact me to sponsor additional features or updates.

Support is offered on a "best effort" basis through the Flarum community thread.

Links


All versions of flarum-ext-scout with dependencies

PHP Build Version
Package Version
Requires flarum/core Version ^1.2
laravel/scout Version ^9.4
algolia/algoliasearch-client-php Version ^3.2
http-interop/http-factory-guzzle Version ^1.0
meilisearch/meilisearch-php Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package clarkwinkelmann/flarum-ext-scout contains the following files

Loading the files please wait ....