<commit_before><?php namespace Flarum\Sticky\Handlers;

use Flarum\Core\Events\DiscussionSearchWillBePerformed;
use Flarum\Categories\CategoryGambit;

class StickySearchModifier
{
    public function subscribe($events)
    {
        $events->listen('Flarum\Core\Events\DiscussionSearchWillBePerformed', __CLASS__.'@reorderSearch');
    }

    public function reorderSearch(DiscussionSearchWillBePerformed $event)
    {
        if ($event->criteria->sort === null) {
            $query = $event->searcher->query();

            if (!is_array($query->orders)) {
                $query->orders = [];
            }

            foreach ($event->searcher->getActiveGambits() as $gambit) {
                if ($gambit instanceof CategoryGambit) {
                    array_unshift($query->orders, ['column' => 'is_sticky', 'direction' => 'desc']);<commit_msg>Fix compatibility with tags extension<commit_after><?php namespace Flarum\Sticky\Handlers;

use Flarum\Core\Events\DiscussionSearchWillBePerformed;
use Flarum\Tags\TagGambit;

class StickySearchModifier
{
    public function subscribe($events)
    {
        $events->listen('Flarum\Core\Events\DiscussionSearchWillBePerformed', __CLASS__.'@reorderSearch');
    }

    public function reorderSearch(DiscussionSearchWillBePerformed $event)
    {
        if ($event->criteria->sort === null) {
            $query = $event->searcher->query();

            if (!is_array($query->orders)) {
                $query->orders = [];
            }

            foreach ($event->searcher->getActiveGambits() as $gambit) {
                if ($gambit instanceof TagGambit) {
                    array_unshift($query->orders, ['column' => 'is_sticky', 'direction' => 'desc']);
{'fraction_non_alphanumeric': 0.1353558926487748, 'fraction_numerical': 0.0, 'mean_word_length': 2.942528735632184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5921116', 'n_tokens_mistral': 506, 'n_tokens_neox': 484, 'n_words': 81}