Skip to content

Commit

Permalink
workaround for flarum/framework#2712
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan committed Apr 17, 2021
1 parent 974b97d commit 7f10a5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
10 changes: 8 additions & 2 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
use Flarum\Extend;
use Flarum\Discussion\Search\DiscussionSearcher;
use Cosname\Search;
use Cosname\Provider;

return [
// Change full-text searcher
//
// See https://github.com/flarum/core/blob/master/tests/integration/extenders/SimpleFlarumSearchTest.php
(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->setFullTextGambit(Search\FulltextGambit::class)
// (new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
// ->setFullTextGambit(Search\FulltextGambit::class)
//
// Right now the method above does not work, see https://discuss.flarum.org/d/26503
// Below is a workaround
(new Extend\ServiceProvider)
->register(Provider\SearchServiceProvider::class)
];
20 changes: 20 additions & 0 deletions src/Provider/SearchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Cosname\Provider;

use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Discussion\Search\DiscussionSearcher;
use Cosname\Search\FulltextGambit;

class SearchServiceProvider extends AbstractServiceProvider
{
public function register()
{
// Workaround for https://github.com/flarum/core/issues/2712
$this->container->extend('flarum.simple_search.fulltext_gambits', function ($oldFulltextGambits) {
$oldFulltextGambits[DiscussionSearcher::class] = FulltextGambit::class;

return $oldFulltextGambits;
});
}
}
2 changes: 1 addition & 1 deletion src/Search/FulltextGambit.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function apply(SearchState $search, $bit)
$query
->addSelect('posts_ft.most_relevant_post_id')
->join(
new Expression('('.$subquery->toSql().') '.$grammar->wrap('posts_ft')),
new Expression('('.$subquery->toSql().') '.$grammar->wrapTable('posts_ft')),
'posts_ft.discussion_id', '=', 'discussions.id'
)
->addBinding($subquery->getBindings(), 'join')
Expand Down

0 comments on commit 7f10a5a

Please sign in to comment.