From 4ecdff8c2dffe793c46330300174e77199e63d3e Mon Sep 17 00:00:00 2001 From: ssmucny Date: Sun, 23 Apr 2023 13:53:44 -0400 Subject: [PATCH] Add query string to event search --- .../src/server/api/endpoints/notes/events/search.ts | 9 +++++++++ packages/frontend/src/pages/search.vue | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/notes/events/search.ts b/packages/backend/src/server/api/endpoints/notes/events/search.ts index 7693cf35cc..70a1df6475 100644 --- a/packages/backend/src/server/api/endpoints/notes/events/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/events/search.ts @@ -9,6 +9,7 @@ import type { Config } from '@/config.js'; import { DI } from '@/di-symbols.js'; import { RoleService } from '@/core/RoleService.js'; import { ApiError } from '../../../error.js'; +import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; export const meta = { tags: ['notes'], @@ -42,6 +43,7 @@ export const meta = { export const paramDef = { type: 'object', properties: { + query: { type: 'string', nullable: true }, sinceId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' }, limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, @@ -93,6 +95,13 @@ export default class extends Endpoint { .innerJoinAndSelect(Event, 'event', 'event.noteId = note.id') .innerJoinAndSelect('note.user', 'user'); + if (ps.query && ps.query.trim() !== '') { + query.andWhere(new Brackets((qb) => { + const q = (ps.query ?? '').trim(); + qb.where('event.title ILIKE :q', { q: `%${ sqlLikeEscape(q) }%` }) + .orWhere('note.text ILIKE :q', { q: `%${ sqlLikeEscape(q) }%` }); + })); + } if (ps.filters) { const filters: Record = ps.filters; diff --git a/packages/frontend/src/pages/search.vue b/packages/frontend/src/pages/search.vue index fe7641cc65..ff33773319 100644 --- a/packages/frontend/src/pages/search.vue +++ b/packages/frontend/src/pages/search.vue @@ -42,6 +42,9 @@
+ + + @@ -105,7 +108,7 @@ onMounted(() => { async function search() { const query = searchQuery.toString().trim(); - // only notes/users search use the query string. event does not use it + // only notes/users search require the query string if ((query == null || query === '') && tab !== 'event') return; if (query.startsWith('https://')) { @@ -149,6 +152,7 @@ async function search() { endpoint: 'notes/events/search', limit: 10, params: { + query: searchQuery, sortBy: eventSort, }, };