PHPackages                             clarkwinkelmann/flarum-ext-scout - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. clarkwinkelmann/flarum-ext-scout

ActiveFlarum-extension[Search &amp; Filtering](/categories/search)

clarkwinkelmann/flarum-ext-scout
================================

Algolia and Meilisearch search for Flarum

0.3.5(3y ago)124.7k↓25.5%8[1 issues](https://github.com/clarkwinkelmann/flarum-ext-scout/issues)[3 PRs](https://github.com/clarkwinkelmann/flarum-ext-scout/pulls)1MITPHP

Since Apr 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/clarkwinkelmann/flarum-ext-scout)[ Packagist](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout)[ RSS](/packages/clarkwinkelmann-flarum-ext-scout/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (12)Used By (1)

Scout Search for Flarum
=======================

[](#scout-search-for-flarum)

[![MIT license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/clarkwinkelmann/flarum-ext-scout/blob/master/LICENSE.md) [![Latest Stable Version](https://camo.githubusercontent.com/334ddd739fd97d7bf8f6540404c737c720586850969672b1b7a99111b44efb8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c61726b77696e6b656c6d616e6e2f666c6172756d2d6578742d73636f75742e737667)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout) [![Total Downloads](https://camo.githubusercontent.com/cf09ee136db5f3443b2306d65e0a1eebe89a17b591948baaa04855f1a89998cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c61726b77696e6b656c6d616e6e2f666c6172756d2d6578742d73636f75742e737667)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout) [![Donate](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.me/clarkwinkelmann)

Integrates [Laravel Scout](https://laravel.com/docs/9.x/scout) with [Flarum](https://flarum.org/) 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](https://www.algolia.com/) and [Meilisearch](https://www.meilisearch.com/) drivers are included in the extension. [TNTSearch](https://github.com/teamtnt/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:

```
php flarum scout:import-all           Import all Flarum models into the search index
                                      (a shortcut to scout:import with every searchable class known to Flarum)
php flarum scout:flush {model}        Flush all of the model's records from the index
php flarum scout:import {model}       Import the given model into the search index
php flarum scout:index {name}         Create an index (generally not needed)
php flarum scout:delete-index {name}  Delete an index (generally not needed)

```

### Algolia

[](#algolia)

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

### Meilisearch

[](#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

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

[](#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 `/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.

- **Max Docs**: this likely impacts how many results Flarum will be able to show for a query
- **Fuziness** (on/off): seems to be the typos/variation matching
- **Fuzziness Levenshtein Distance**
- **Fuzziness Prefix Length**: no idea what it does
- **Fuzziness Max Expansions** no idea what it does

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

Installation
------------

[](#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
-------------------------------

[](#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

[](#discussions)

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

- **Title**: support built into Scout.
- **Formulaire Discussion Fields**: supported since Formulaire 1.8 (guest-accessible forms only).

### Posts

[](#posts)

- **Content**: support built into Scout, the value used is a plain text version of the output HTML without any tag. Some information like link URLs, image URLs and image alts are therefore not indexed. This might be changed in a future version.

### Users

[](#users)

- **Display Name**: support built into Scout.
- **Username**: support built into Scout.
- **FoF Bio**: support built into Scout (not in FoF Bio itself).
- **Formulaire Profile Fields**: supported since Formulaire 1.8 (guest-accessible forms only).

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

### Formulaire

[](#formulaire)

Forms and Submissions are optionally indexed via Scout. See [Formulaire documentation](https://kilowhat.net/flarum/extensions/formulaire#scout-integration) for details.

Developers
----------

[](#developers)

### Extend the search index of existing models

[](#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.

```
