Add query string to event search

This commit is contained in:
ssmucny 2023-04-23 13:53:44 -04:00
parent a967c0268e
commit 4ecdff8c2d
2 changed files with 14 additions and 1 deletions

View File

@ -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<typeof meta, typeof paramDef> {
.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<string, (string | null)[]> = ps.filters;

View File

@ -42,6 +42,9 @@
<MkSpacer v-else-if="tab === 'event'" :content-max="800">
<div class="_gaps">
<div class="_gaps">
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
<template #prefix><i class="ti ti-search"></i></template>
</MkInput>
<MkSelect v-model="eventSort" small>
<template #label>{{ 'Sort By' }}</template>
<option value="startDate">{{ 'Event Date' }}</option>
@ -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,
},
};