<NME> UserSearch.php
<BEF> <?php

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Libraries\Search;

use App\Libraries\Elasticsearch\BoolQuery;
use App\Libraries\Elasticsearch\RecordSearch;
use App\Models\User;

class UserSearch extends RecordSearch
{
    public function __construct(?UserSearchParams $params = null)
    {
        parent::__construct(
            User::esIndexName(),
            $params ?? new UserSearchParams(),
            User::class
        );
    }

    public function records()
    {
        return $this->response()->records()->with(['country', 'userProfileCustomization', 'userGroups'])->get();
    }

    /**
     * {@inheritdoc}
     */
    public function getQuery()
    {
        static $lowercase_stick = [
            'analyzer' => 'username_lower',
        );

        $this->queryString = $this->options['query'] ?? '';
    }

    /**
            'fields' => ['username', 'username._*'],
        ];

        $query = (new BoolQuery())
            ->mustNot(['terms' => ['_id' => $this->params->blockedUserIds()]])
            ->mustNot(['term' => ['is_old' => true]])
            ->filter(['term' => ['user_warnings' => 0]])
            ->filter(['term' => ['user_type' => 0]]);

        if ($this->params->queryString !== null) {
            $query->shouldMatch(1)
                ->should(['term' => ['_id' => ['value' => $this->params->queryString, 'boost' => 100]]])
                ->should(['match' => ['username.raw' => ['query' => $this->params->queryString, 'boost' => 5]]])
                ->should(['match' => ['previous_usernames' => ['query' => $this->params->queryString]]])
                ->should(['multi_match' => array_merge(['query' => $this->params->queryString], $lowercase_stick)])
                ->should(['multi_match' => array_merge(['query' => $this->params->queryString], $whitespace_stick)])
                ->should(['match_phrase' => ['username._slop' => $this->params->queryString]]);
        }

        if ($this->params->recentOnly) {
            $query->filter([
                'range' => [
                    'user_lastvisit' => [
            ->filter(['term' => ['user_warnings' => 0]])
            ->filter(['term' => ['user_type' => 0]]);

        $this->query($query);

        return parent::toArray();

<MSG> add recently active filter to user search

<DFF> @@ -35,6 +35,7 @@ class UserSearch extends RecordSearch
         );
 
         $this->queryString = $this->options['query'] ?? '';
+        $this->recentOnly = $this->options['recentOnly'] ?? false;
     }
 
     /**
@@ -64,6 +65,16 @@ class UserSearch extends RecordSearch
             ->filter(['term' => ['user_warnings' => 0]])
             ->filter(['term' => ['user_type' => 0]]);
 
+        if ($this->recentOnly) {
+            $query->filter([
+                'range' => [
+                    'user_lastvisit' => [
+                        'gte' => 'now-90d'
+                    ],
+                ],
+            ]);
+        }
+
         $this->query($query);
 
         return parent::toArray();

{'addition_count': 11, 'commit_subject': 'add recently active filter to user search', 'deletion_count': 0, 'file_extension': '.php', 'lang': 'php', 'license': 'agpl-3.0', 'repo_name': 'ppy/osu-web'}