Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Apr 27, 2022
0 parents commit 4f62759
Show file tree
Hide file tree
Showing 27 changed files with 3,116 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
[*.md]
indent_size = 2
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
js/src export-ignore
.git* export-ignore

js/dist/*.js -diff
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
vendor
composer.lock
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Clark Winkelmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Scout Search for Flarum

[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/clarkwinkelmann/flarum-ext-scout/blob/master/LICENSE.md) [![Latest Stable Version](https://img.shields.io/packagist/v/clarkwinkelmann/flarum-ext-scout.svg)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout) [![Total Downloads](https://img.shields.io/packagist/dt/clarkwinkelmann/flarum-ext-scout.svg)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout) [![Donate](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/clarkwinkelmann)

Integrates [Laravel Scout](https://laravel.com/docs/9.x/scout) with [Flarum](https://flarum.org/) discussion and user search.

Algolia and Meilisearch drivers are included in the extension.
The Scout database and collection drivers cannot be used (they would be worst than Flarum's built-in database search).

For convenience, this extension already includes the PHP SDK of both Algolia and Meilisearch.
However, if you are not running the latest MeiliSearch version you might need to explicitely install an older version of the SDK.

If you are regularly running `composer update` on all your dependencies, you should 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.

While only discussion 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, however you need to replace the model class names with the special classes built into this extension (`Flarum\User\User` becomes `ClarkWinkelmann\Scout\Model\User`, `Flarum\Discussion\Discussion` becomes `ClarkWinkelmann\Scout\Model\Discussion`, etc.):

```
php flarum scout:import-all Import all Flarum models into the search index
(a shortcut to scout:import with all the correct class names)
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)
```

## Installation

> This extension is still experimental. Please test on a staging server first.
> I have not tested Algolia or async queues yet.
composer require clarkwinkelmann/flarum-ext-scout

## 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](https://clarkwinkelmann.com/flarum) to sponsor additional features or updates.

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

## Links

- [GitHub](https://github.com/clarkwinkelmann/flarum-ext-scout)
- [Packagist](https://packagist.org/packages/clarkwinkelmann/flarum-ext-scout)
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "clarkwinkelmann/flarum-ext-scout",
"description": "Algolia and Meilisearch search for Flarum",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": "^1.2",
"laravel/scout": "^9.4",
"algolia/algoliasearch-client-php": "^3.2",
"http-interop/http-factory-guzzle": "^1.0",
"meilisearch/meilisearch-php": "*"
},
"authors": [
{
"name": "Clark Winkelmann",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"source": "https://github.com/clarkwinkelmann/flarum-ext-scout"
},
"autoload": {
"psr-4": {
"ClarkWinkelmann\\Scout\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"extra": {
"flarum-extension": {
"title": "Scout Search",
"category": "feature",
"icon": {
"name": "fas fa-search",
"backgroundColor": "#f47f68",
"color": "#fff"
}
}
}
}
30 changes: 30 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ClarkWinkelmann\Scout;

use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Extend;
use Flarum\User\Search\UserSearcher;
use Laravel\Scout\Console as ScoutConsole;

return [
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),

new Extend\Locales(__DIR__ . '/resources/locale'),

(new Extend\ServiceProvider())
->register(ScoutServiceProvider::class),

(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->setFullTextGambit(Search\DiscussionGambit::class),
(new Extend\SimpleFlarumSearch(UserSearcher::class))
->setFullTextGambit(Search\UserGambit::class),

(new Extend\Console())
->command(Console\ImportAll::class)
->command(ScoutConsole\FlushCommand::class)
->command(ScoutConsole\ImportCommand::class)
->command(ScoutConsole\IndexCommand::class)
->command(ScoutConsole\DeleteIndexCommand::class),
];
1 change: 1 addition & 0 deletions js/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/admin';
2 changes: 2 additions & 0 deletions js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/dist/admin.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@clarkwinkelmann/scout",
"private": true,
"dependencies": {
"flarum-tsconfig": "^1.0",
"flarum-webpack-config": "^2.0",
"webpack": "^5.65",
"webpack-cli": "^4.9"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
}
}
57 changes: 57 additions & 0 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import app from 'flarum/admin/app';

app.initializers.add('clarkwinkelmann-scout', () => {
app.extensionData.for('clarkwinkelmann-scout')
.registerSetting({
type: 'select',
setting: 'clarkwinkelmann-scout.driver',
options: {
null: app.translator.trans('clarkwinkelmann-scout.admin.setting.driverOption.null'),
algolia: app.translator.trans('clarkwinkelmann-scout.admin.setting.driverOption.algolia'),
meilisearch: app.translator.trans('clarkwinkelmann-scout.admin.setting.driverOption.meilisearch'),
},
default: 'null',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.driver'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.prefix',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.prefix'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.algoliaId',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.algoliaId'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.algoliaSecret',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.algoliaSecret'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.algoliaConnectTimeout',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.algoliaConnectTimeout'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.algoliaReadTimeout',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.algoliaReadTimeout'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.algoliaWriteTimeout',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.algoliaWriteTimeout'),
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.meilisearchHost',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.meilisearchHost'),
placeholder: '127.0.0.1:7700',
})
.registerSetting({
type: 'text',
setting: 'clarkwinkelmann-scout.meilisearchKey',
label: app.translator.trans('clarkwinkelmann-scout.admin.setting.meilisearchKey'),
});
});
16 changes: 16 additions & 0 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "flarum-tsconfig",
"include": [
"src/**/*",
"../vendor/flarum/core/js/dist-typings/@types/**/*"
],
"files": [],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"flarum/*": [
"../vendor/flarum/core/js/dist-typings/*"
]
}
}
}
1 change: 1 addition & 0 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('flarum-webpack-config')();
Loading

0 comments on commit 4f62759

Please sign in to comment.