If a search parameter is present (filter.q), send requests to the search endpoint instead of the filter endpoint

This commit is contained in:
Alexander Skvortsov 2020-11-12 14:29:00 -05:00
parent 0172008693
commit 87d2f3d246
5 changed files with 13 additions and 8 deletions

View File

@ -83,7 +83,7 @@ export default class Store {
*/
find(type, id, query = {}, options = {}) {
let params = query;
let url = app.forum.attribute('apiUrl') + '/' + type;
let url = app.forum.attribute('apiUrl') + (query.search ? '/search/' : '/') + type;
if (id instanceof Array) {
url += '?filter[id]=' + id.join(',');

View File

@ -24,7 +24,7 @@ export default class DiscussionsSearchSource {
include: 'mostRelevantPost',
};
return app.store.find('discussions', params).then((results) => (this.results[query] = results));
return app.store.find('discussions', params, { search: query }).then((results) => (this.results[query] = results));
}
view(query) {

View File

@ -16,10 +16,14 @@ export default class UsersSearchResults {
search(query) {
return app.store
.find('users', {
filter: { q: query },
page: { limit: 5 },
})
.find(
'users',
{
filter: { q: query },
page: { limit: 5 },
},
{ search: query }
)
.then((results) => {
this.results[query] = results;
m.redraw();

View File

@ -119,7 +119,7 @@ export default class DiscussionListState {
params.page = { offset };
params.include = params.include.join(',');
return this.app.store.find('discussions', params);
return this.app.store.find('discussions', params, { search: params.filter.q });
}
/**

View File

@ -11,6 +11,7 @@ namespace Flarum\Forum\Content;
use Flarum\Api\Client;
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Controller\SearchDiscussionsController;
use Flarum\Frontend\Document;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
@ -114,6 +115,6 @@ class Index
*/
private function getApiDocument(User $actor, array $params)
{
return json_decode($this->api->send(ListDiscussionsController::class, $actor, $params)->getBody());
return json_decode($this->api->send(($params['filter']['q'] ? SearchDiscussionsController::class : ListDiscussionsController::class), $actor, $params)->getBody());
}
}