Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search implementation overhaul #2857

Merged
merged 193 commits into from Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
38135fc
move user search-related methods to own trait
notbakaneko Feb 7, 2018
be0b441
start switching UserSearch to use SearchResponse
notbakaneko Feb 7, 2018
a298363
use Query to build query.
notbakaneko Feb 7, 2018
bd4a949
probably should match at least 1
notbakaneko Feb 7, 2018
0732029
move Beatmapset search code to separate file
notbakaneko Feb 8, 2018
58f4f4a
use Search and Query in Wiki\Page
notbakaneko Feb 8, 2018
170890e
moving beatmapset search to use newer search interface
notbakaneko Feb 8, 2018
1668d6e
use Query to build query
notbakaneko Feb 8, 2018
7205e45
make use SearchResponse in Beatmapset search
notbakaneko Feb 8, 2018
90c8d1d
actually, own classes for search might be a better idea..
notbakaneko Feb 9, 2018
ca1cdb5
search returns a Search object.
notbakaneko Feb 9, 2018
c865a70
apply Search to Wiki\Page
notbakaneko Feb 9, 2018
0a46537
camel_case method name
notbakaneko Feb 13, 2018
67c0f3a
call methods on search object instead of array accessor
notbakaneko Feb 13, 2018
7c4cb9e
let search subclasses handle paginator?
notbakaneko Feb 13, 2018
9987dc0
less paginate($mode)
notbakaneko Feb 13, 2018
f12ebb9
let page parser thing on handle the offset
notbakaneko Feb 13, 2018
4ea4d58
let search using LengthAwarePaginator to work like LengthAwarePaginat…
notbakaneko Feb 13, 2018
eccee3b
default page size const
notbakaneko Feb 14, 2018
6496c6c
remove compatibility shim
notbakaneko Feb 14, 2018
d21d0f8
move search classes to their own namespace
notbakaneko Feb 14, 2018
25fc730
response() called too early
notbakaneko Feb 14, 2018
063e9c5
Make quick search its own thing
notbakaneko Feb 14, 2018
fb63749
Search is now AllSearch
notbakaneko Feb 14, 2018
7df4df1
make counts work again
notbakaneko Feb 14, 2018
45a9c9d
add WebSearchable interface.
notbakaneko Feb 14, 2018
6d16dd6
unused?
notbakaneko Feb 14, 2018
984e9a0
fix the timings later
notbakaneko Feb 14, 2018
b2f9bfe
was renamed
notbakaneko Mar 1, 2018
805c627
use size instead of limit
notbakaneko Mar 1, 2018
0a40022
overLimit() call needs fixing
notbakaneko Mar 1, 2018
fc5964c
placeholder function for checking validity of query string
notbakaneko Mar 1, 2018
e039d3e
private after public
notbakaneko Mar 1, 2018
5010b2a
start moving beatmap search initializers to constructor
notbakaneko Mar 1, 2018
fe220cf
is called BoolQuery now
notbakaneko Mar 1, 2018
df3a765
de-staticing the query building
notbakaneko Mar 1, 2018
c95e4fa
extracting sort parameters to be applied separately
notbakaneko Mar 1, 2018
8a02fb9
Merge branch 'master' into feature/search-update-calls
notbakaneko Mar 16, 2018
687f17d
move search class compatiblity interface into a trait
notbakaneko Mar 16, 2018
ed6baca
move total() to base class
notbakaneko Mar 16, 2018
2ea8c4c
move HIGHLIGHT_FRAGMENT_SIZE constant to base class
notbakaneko Mar 16, 2018
486d273
move highlight implosion logic out of blade
notbakaneko Mar 16, 2018
7a6639d
maybe normalize params separate from search
notbakaneko Mar 20, 2018
279d2ad
add count query for searches
notbakaneko Mar 20, 2018
90f3677
update UserSearch calls
notbakaneko Mar 21, 2018
e38b7b4
whoops
notbakaneko Mar 21, 2018
dbf0cb7
update WikiSearch
notbakaneko Mar 21, 2018
7b3da2e
fix using wrong variable
notbakaneko Mar 21, 2018
e96972f
reworking all search
notbakaneko Mar 21, 2018
daa217f
seems unnecessary?
notbakaneko Mar 21, 2018
956f69b
restore pager
notbakaneko Mar 21, 2018
5b8443e
move the looping into the per-type views
notbakaneko Mar 21, 2018
9e4179b
pagination
notbakaneko Mar 21, 2018
f66d061
limit results in all search
notbakaneko Mar 21, 2018
02a3041
appends does nothing if we're not assigning to anything
notbakaneko Mar 21, 2018
933acc6
filter out searches that should be visible
notbakaneko Mar 21, 2018
6e8005d
use counts from existing searches
notbakaneko Mar 21, 2018
f24c7d8
No need to get full response if only the counts are needed.
notbakaneko Mar 21, 2018
ab326b5
move forum search results below wiki results.
notbakaneko Mar 21, 2018
a6003a2
...unused?
notbakaneko Mar 21, 2018
0e7a35f
cleaning up Beatmapset search calls
notbakaneko Mar 21, 2018
df1bd03
Add a paginator where you can get the original search object.
notbakaneko Mar 22, 2018
9b82a87
forum search options missing >_>
notbakaneko Mar 22, 2018
1e1c764
actually, let's not use that terrible paginator interface.
notbakaneko Mar 22, 2018
d2ccd25
overrideable default query size
notbakaneko Mar 22, 2018
de931b3
probably unused (or will be)
notbakaneko Mar 22, 2018
3c9be00
make quick search work again
notbakaneko Mar 22, 2018
486ee96
move type-dependent layout to type-specific blade
notbakaneko Mar 22, 2018
5a0b2a6
rename blades
notbakaneko Mar 22, 2018
15c93b3
hide side link if not all search
notbakaneko Mar 22, 2018
b229e96
normalize params in constructor
notbakaneko Mar 22, 2018
7c4330c
adding Sort class, rename $sort to $sorts
notbakaneko Mar 23, 2018
61f605b
refactor query sort generation
notbakaneko Mar 23, 2018
36f5791
status filters are now a ..filter
notbakaneko Mar 23, 2018
10b9831
query helper for query_string
notbakaneko Mar 23, 2018
028b7f1
rank request querystring should be parsed before given to search.
notbakaneko Mar 23, 2018
cd3ab4f
refactor rank query filter
notbakaneko Mar 23, 2018
63630ce
call the filters the same way
notbakaneko Mar 23, 2018
7568713
refactor to more filters
notbakaneko Mar 23, 2018
c911665
video/storyboard filter request query string should be parsed before …
notbakaneko Mar 23, 2018
093d88c
some reordering
notbakaneko Mar 23, 2018
65ae71a
whoops
notbakaneko Mar 23, 2018
b8f046f
remove normalizeParams()
notbakaneko Mar 23, 2018
5d9dac2
bye DEFAULT_PAGE_SIZE
notbakaneko Mar 23, 2018
5924740
Merge branch 'master' into feature/search-update-calls
notbakaneko Mar 26, 2018
02eabf2
return a new copy when remapping
notbakaneko Mar 26, 2018
44bb65e
explode general options
notbakaneko Mar 26, 2018
8190356
add include converts and show recommended filters back into Beatmapse…
notbakaneko Mar 26, 2018
c696ae5
override toArray() instead of using static builder in constructor.
notbakaneko Mar 26, 2018
2d07636
merge fail
notbakaneko Mar 26, 2018
71413f3
add recently active filter to user search
notbakaneko Mar 26, 2018
f974831
quick search defaults to recently active users.
notbakaneko Mar 26, 2018
9cdb14b
auto resolve paginator path if not set
notbakaneko Mar 26, 2018
9e0cf71
update PostSearch to work
notbakaneko Mar 26, 2018
69f4062
really should be an unscored filter.
notbakaneko Mar 26, 2018
2e83848
shouldn't need ArrayAccess anymore
notbakaneko Mar 26, 2018
1650fa2
move PostSearch namespace
notbakaneko Mar 26, 2018
628a5d8
_routing is deprecated
notbakaneko Mar 27, 2018
719e03f
use ?? null instead of ?? ''
notbakaneko Mar 28, 2018
f517995
need a non-abstract basic search class
notbakaneko Mar 28, 2018
5e87e61
can use hit result directly
notbakaneko Mar 28, 2018
ef56fa0
response is iterable
notbakaneko Mar 28, 2018
0f5ec8c
shouldn't be setting fallback in consturctor
notbakaneko Mar 28, 2018
da34d2d
rip es_search helper
notbakaneko Mar 28, 2018
e549761
should be deleted
notbakaneko Mar 28, 2018
b0bb4c4
report Search::fetch() timings
notbakaneko Mar 28, 2018
29e599e
record beatmapset search run time.
notbakaneko Mar 28, 2018
d3d3e15
unneeded use
notbakaneko Mar 28, 2018
1c0c82c
limit user search to 100 results
notbakaneko Mar 28, 2018
393d449
move protected function above private
notbakaneko Mar 28, 2018
42cacc5
Merge branch 'master' into feature/search-update-calls
notbakaneko Mar 29, 2018
73331fc
create BeatmapsetSearchRequestParams to handle http request params fo…
notbakaneko Mar 29, 2018
4621ed2
add cache key support to search request params object
notbakaneko Mar 29, 2018
727c66e
cache the entire json output instead of just the search response.
notbakaneko Mar 29, 2018
e47cf77
use json_encode instead
notbakaneko Mar 29, 2018
19d5c03
wrap cache-or-not-fetch into a function
notbakaneko Mar 29, 2018
4d32036
add UserSearchRequestParams class
notbakaneko Mar 29, 2018
a16e886
unbreak MultiSearch
notbakaneko Mar 29, 2018
1f510ba
ForumSearchRequestParams
notbakaneko Mar 29, 2018
0d55e1b
PostSearchRequestParams
notbakaneko Mar 29, 2018
c807df7
PostSearchRequestParams
notbakaneko Mar 29, 2018
953c352
unused
notbakaneko Mar 29, 2018
89d479f
WikiSearchRequestParams
notbakaneko Mar 29, 2018
3291063
SearchRequestParams is too wordy and doesn't handle just request params.
notbakaneko Mar 29, 2018
3bace2a
use SearchParams type in constructor instead of array.
notbakaneko Mar 29, 2018
a51cab7
add some phpdoc and type hints
notbakaneko Mar 30, 2018
0db206f
move base SearchParams class elasticsearch namespace
notbakaneko Mar 30, 2018
09b781c
change fetchCacheable parameter to prefix instead of cacheKey
notbakaneko Mar 30, 2018
b038f12
hard to see error if not included in response at the moment.
notbakaneko Mar 30, 2018
d38593a
don't explode on null query string
notbakaneko Mar 30, 2018
9f468a6
null and empty string query terms are not the same
notbakaneko Mar 30, 2018
ff347fb
don't try to count if minimum length not met
notbakaneko Mar 30, 2018
c1f1144
don't need currentQuery()
notbakaneko Mar 30, 2018
81d2a55
explict params type.
notbakaneko Mar 30, 2018
c235cd9
allow page, size, sort in search params; fluent interface should over…
notbakaneko Mar 30, 2018
3a6fef7
not needed
notbakaneko Mar 30, 2018
87dbbf1
empty string request in this case should be considered null
notbakaneko Mar 30, 2018
0e07bf9
remove compatibility
notbakaneko Mar 30, 2018
1ac68a4
need empty search params
notbakaneko Mar 30, 2018
c6458c8
fix use order
notbakaneko Mar 30, 2018
02ed6aa
not being used anywhere
notbakaneko Mar 30, 2018
96ce51b
...don't actually need user?
notbakaneko Mar 30, 2018
62286a2
reduce forum search page size to 20
notbakaneko Mar 30, 2018
8db5b4e
fix copy paste fail
notbakaneko Mar 30, 2018
5d6020a
don't need limit
notbakaneko Mar 30, 2018
5eeecd9
make search-result__entry its own block
notbakaneko Mar 30, 2018
8d23fe7
this query would work a lot better if it actually added the filter
notbakaneko Mar 30, 2018
c081734
pass params from AllSearch through fromRequest()
notbakaneko Mar 30, 2018
7b42592
update new files to 2018
notbakaneko Mar 30, 2018
14fef94
make StyleCI happy
notbakaneko Mar 30, 2018
60d2a26
should be passing whole request
notbakaneko Apr 2, 2018
821edde
user not required
notbakaneko Apr 2, 2018
8fabcff
accidentally deleted the topic if search
notbakaneko Apr 2, 2018
aa46987
not needed either
notbakaneko Apr 2, 2018
de6bab0
getting Request index offsets doesn't require ?? null
notbakaneko Apr 3, 2018
8b10762
request params should be casted on parse
notbakaneko Apr 4, 2018
313da1c
shouldn't be overriding $this->query anymore
notbakaneko Apr 4, 2018
f729001
shouldn't be calling toArray() here anymore
notbakaneko Apr 4, 2018
78e6c5a
declare default sort if sort is not specified
notbakaneko Apr 4, 2018
ba312d4
set PostSearch's highlight in constructor instead of query builder
notbakaneko Apr 4, 2018
0d1a229
type hint should be a nullable
notbakaneko Apr 4, 2018
4433fed
. very important to styleci
notbakaneko Apr 4, 2018
e7f4b4a
Merge branch 'master' into feature/search-update-calls
notbakaneko Apr 5, 2018
ea38251
empty string mode needs to be handled
notbakaneko Apr 5, 2018
2c057a3
that was backwards
notbakaneko Apr 5, 2018
8fe7241
actually default sort can be determined ahead of time
notbakaneko Apr 5, 2018
100499c
should look at accepting an array of Sort as params
notbakaneko Apr 5, 2018
bd6a112
normalize beatmap search sort in params
notbakaneko Apr 5, 2018
51e47fb
Merge branch 'master' into feature/search-update-calls
notbakaneko Apr 9, 2018
0bc83d6
allow _source to be applied through param options
notbakaneko Apr 11, 2018
4847bc7
quick search doesn't exist right now.
notbakaneko Apr 11, 2018
cee329b
looks unused :D
notbakaneko Apr 11, 2018
f6e4372
inline calls
notbakaneko Apr 11, 2018
9804142
pass $limit
notbakaneko Apr 11, 2018
28c9a2c
Merge branch 'master' into feature/search-update-calls
notbakaneko Apr 12, 2018
04616e5
workaround for separate count query being run when it shouldn't.
notbakaneko Apr 12, 2018
6a93167
BeatmapsetTransformer output can't be output cached at the moment :(
notbakaneko Apr 12, 2018
c232cd5
move block
notbakaneko Apr 12, 2018
9b80b83
use subclasses instead of fromRequest methods
notbakaneko Apr 16, 2018
48b6af8
BasicSearch needs to implement getQuery()
notbakaneko Apr 17, 2018
3015735
always be EmptySearchParams
notbakaneko Apr 17, 2018
364f4fe
don't need the fromArray parser at the moment
notbakaneko Apr 17, 2018
164ce7b
use a default set of params if none provided
notbakaneko Apr 17, 2018
bee3b93
unused use
notbakaneko Apr 17, 2018
ea0970e
Merge branch 'master' into feature/search-update-calls
peppy Apr 17, 2018
015c312
let sort() be able to handle arrays of Sort
notbakaneko Apr 18, 2018
8c99750
$active input parameter was removed a while ago
notbakaneko Apr 18, 2018
9a7e354
overrideable max results.
notbakaneko Apr 18, 2018
7881226
move $type to the end, because...
notbakaneko Apr 18, 2018
bbfdd7e
idField should be supported too.
notbakaneko Apr 18, 2018
25069e9
users are not beatmapsets
notbakaneko Apr 20, 2018
3ea112f
Merge branch 'master' into feature/search-update-calls
nekodex Apr 20, 2018
919b4e7
include country and userProfileCustomization with records
notbakaneko Apr 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 19 additions & 39 deletions app/Http/Controllers/BeatmapsetsController.php
Expand Up @@ -21,6 +21,8 @@
namespace App\Http\Controllers;

use App\Jobs\NotifyBeatmapsetUpdate;
use App\Libraries\Search\BeatmapsetSearch;
use App\Libraries\Search\BeatmapsetSearchRequestParams;
use App\Models\Beatmap;
use App\Models\BeatmapDownload;
use App\Models\BeatmapMirror;
Expand All @@ -43,11 +45,8 @@ public function index()
{
$languages = Language::listing();
$genres = Genre::listing();
$beatmaps = json_collection(
Beatmapset::search($this->searchParams())['data'],
new BeatmapsetTransformer,
'beatmaps'
);

$beatmaps = $this->search();

// temporarily put filters here
$general = [
Expand Down Expand Up @@ -133,13 +132,24 @@ public function show($id)

public function search()
{
$user = Auth::user();
$params = new BeatmapsetSearchRequestParams(request(), Auth::user());

$params = $this->searchParams();
$beatmaps = Beatmapset::search($params)['data'];
$records = datadog_timing(function () use ($params) {
$ids = $params->fetchCacheable(
'search-cache:',
config('osu.beatmapset.es_cache_duration'),
function () use ($params) {
$search = (new BeatmapsetSearch($params))->source('_id');

return $search->response()->ids();
}
);

return Beatmapset::whereIn('beatmapset_id', $ids)->orderByField('beatmapset_id', $ids)->get();
}, config('datadog-helper.prefix_web').'.search', ['type' => 'beatmapset']);

return json_collection(
$beatmaps,
$records,
new BeatmapsetTransformer,
'beatmaps'
);
Expand Down Expand Up @@ -270,34 +280,4 @@ public function updateFavourite($id)
'favourited' => $user->fresh()->hasFavourited($beatmapset),
];
}

private function searchParams()
{
$user = Auth::user();

if ($user === null) {
$params = [
'page' => Request::input('page'),
];
} else {
$params = [
'general' => Request::input('c'),
'query' => Request::input('q'),
'mode' => Request::input('m'),
'status' => Request::input('s'),
'genre' => Request::input('g'),
'language' => Request::input('l'),
'extra' => Request::input('e'),
'page' => Request::input('page'),
'sort' => Request::input('sort'),
'user' => $user,
];

if ($user->isSupporter()) {
$params['rank'] = Request::input('r');
}
}

return $params;
}
}
31 changes: 4 additions & 27 deletions app/Http/Controllers/HomeController.php
Expand Up @@ -22,7 +22,7 @@

use App;
use App\Libraries\CurrentStats;
use App\Libraries\Search;
use App\Libraries\Search\AllSearch;
use App\Models\BeatmapDownload;
use App\Models\Beatmapset;
use App\Models\Forum\Post;
Expand All @@ -43,7 +43,6 @@ public function __construct()
'only' => [
'downloadQuotaCheck',
'search',
'quickSearch',
],
]);

Expand Down Expand Up @@ -121,38 +120,16 @@ public function osuSupportPopup()
return view('objects._popup_support_osu');
}

public function quickSearch()
{
$search = new Search([
'query' => Request::input('query'),
'limit' => 5,
]);

if (!$search->hasQuery()) {
return response([], 204);
}

return view('home.nav_search_result', compact('search'));
}

public function search()
{
if (request('mode') === 'beatmapset') {
return ujs_redirect(route('beatmapsets.index', ['q' => Request::input('query')]));
return ujs_redirect(route('beatmapsets.index', ['q' => request('query')]));
}

$params = array_merge(Request::all(), [
'user' => Auth::user(),
]);

$search = new Search($params);
$allSearch = new AllSearch(request(), ['user' => Auth::user()]);
$isSearchPage = true;

if ($search->mode === Search::DEFAULT_MODE) {
$search->params['limit'] = 8;
}

return view('home.search', compact('search', 'isSearchPage'));
return view('home.search', compact('allSearch', 'isSearchPage'));
}

public function setLocale()
Expand Down
18 changes: 7 additions & 11 deletions app/Http/Controllers/UsersController.php
Expand Up @@ -20,7 +20,8 @@

namespace App\Http\Controllers;

use App\Libraries\PostSearch;
use App\Libraries\Search\PostSearch;
use App\Libraries\Search\PostSearchRequestParams;
use App\Libraries\UserRegistration;
use App\Models\Achievement;
use App\Models\Beatmap;
Expand All @@ -34,6 +35,7 @@
use App\Models\User;
use App\Models\UserNotFound;
use Auth;
use Illuminate\Pagination\LengthAwarePaginator;
use Request;

class UsersController extends Controller
Expand Down Expand Up @@ -216,17 +218,11 @@ public function posts($id)
abort(404);
}

$options = [
'query' => trim(request('query')),
'userId' => $user->getKey(),
'forumId' => request('forum_id'),
'includeSubforums' => get_bool(request('forum_children')),
];

$search = new PostSearch($options);
$page = $search->paginate(50)->appends(request()->query());
$search = (new PostSearch(new PostSearchRequestParams(request(), $user)))
->size(50)
->page(LengthAwarePaginator::resolveCurrentPage());

return view('users.posts', compact('search', 'page', 'user'));
return view('users.posts', compact('search', 'user'));
}

public function kudosu($_userId)
Expand Down
4 changes: 3 additions & 1 deletion app/Libraries/Elasticsearch/HasChildQuery.php
Expand Up @@ -57,7 +57,9 @@ public function toArray() : array
'name' => $this->name,
'from' => $pageParams['from'],
'size' => $pageParams['size'],
'sort' => $this->sort,
'sort' => array_map(function ($sort) {
return $sort->toArray();
}, $this->sorts),
];

if (isset($this->highlight)) {
Expand Down
81 changes: 56 additions & 25 deletions app/Libraries/Elasticsearch/HasSearch.php
Expand Up @@ -25,8 +25,8 @@ trait HasSearch
protected $from;
protected $highlight;
protected $query;
protected $size = 10;
protected $sort = [];
protected $size;
protected $sorts = [];
protected $source;
protected $type;

Expand All @@ -53,7 +53,7 @@ public function limit(?int $limit)
*/
public function size(?int $size)
{
$this->size = clamp($size ?? 50, 1, 50);
$this->size = $size;

return $this;
}
Expand All @@ -68,26 +68,6 @@ public function page(?int $page)
return $this;
}

/**
* page is not returned if using offset query.
*
* @return array
*/
protected function getPaginationParams()
{
$params = ['size' => $this->size, 'limit' => $this->size];

// from overrides page.
if (isset($this->from)) {
$params['from'] = $this->from;
} else {
$params['page'] = max(1, $this->page ?? 1);
$params['from'] = ($params['page'] - 1) * $this->size;
}

return $params;
}

/**
* @param Highlight $highlight the fields and settings for highlighting. Set to null to remove.
*
Expand Down Expand Up @@ -126,11 +106,19 @@ public function source($fields)
}

/**
* @param array|Sort $sort
*
* @return $this
*/
public function sort(array $sort)
public function sort($sort)
{
$this->sort[] = $sort;
if (is_array($sort)) {
foreach ($sort as $s) {
$this->addSort($s);
}
} else {
$this->addSort($sort);
}

return $this;
}
Expand All @@ -144,4 +132,47 @@ public function type(?string $type)

return $this;
}

protected function getDefaultSize() : int
{
return 10;
}

/**
* page is not returned if using offset query.
*
* @return array
*/
protected function getPaginationParams()
{
$size = $this->getSize();
$params = ['size' => $size];

// from overrides page.
if (isset($this->from)) {
$params['from'] = $this->from;
} else {
$params['page'] = max(1, $this->page ?? 1);
$params['from'] = ($params['page'] - 1) * $size;
}

return $params;
}

/**
* Gets the actual size to use in queries.
*
* @return int actual size to use.
*/
protected function getSize() : int
{
return $this->size ?? $this->getDefaultSize();
}

private function addSort(Sort $sort)
{
if (!$sort->isBlank()) {
$this->sorts[] = $sort;
}
}
}
2 changes: 1 addition & 1 deletion app/Libraries/Elasticsearch/Hit.php
Expand Up @@ -66,7 +66,7 @@ public function highlights(string $field, ?int $limit = null)
}

// highlights are stored in an array, so return an array as well.
return [html_excerpt($this['_source'][$field])];
return [html_excerpt($this['_source'][$field], $limit)];
}

public function innerHits(string $name)
Expand Down
50 changes: 50 additions & 0 deletions app/Libraries/Elasticsearch/RecordSearch.php
@@ -0,0 +1,50 @@
<?php

/**
* Copyright 2015-2018 ppy Pty. Ltd.
*
* This file is part of osu!web. osu!web is distributed with the hope of
* attracting more community contributions to the core ecosystem of osu!.
*
* osu!web is free software: you can redistribute it and/or modify
* it under the terms of the Affero GNU General Public License version 3
* as published by the Free Software Foundation.
*
* osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with osu!web. If not, see <http://www.gnu.org/licenses/>.
*/

namespace App\Libraries\Elasticsearch;

abstract class RecordSearch extends Search
{
protected $idField;
protected $recordType;

public function __construct(string $index, SearchParams $params, $recordType, $idField = '_id')
{
parent::__construct($index, $params);

$this->idField = $idField;
$this->recordType = $recordType;
}

public function data()
{
return $this->records();
}

public function records()
{
return $this->response()->records()->get();
}

public function response() : SearchResponse
{
return parent::response()->recordType($this->recordType)->idField($this->idField);
}
}