Add query string to event search
This commit is contained in:
parent
a967c0268e
commit
4ecdff8c2d
|
@ -9,6 +9,7 @@ import type { Config } from '@/config.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { RoleService } from '@/core/RoleService.js';
|
import { RoleService } from '@/core/RoleService.js';
|
||||||
import { ApiError } from '../../../error.js';
|
import { ApiError } from '../../../error.js';
|
||||||
|
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['notes'],
|
tags: ['notes'],
|
||||||
|
@ -42,6 +43,7 @@ export const meta = {
|
||||||
export const paramDef = {
|
export const paramDef = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
query: { type: 'string', nullable: true },
|
||||||
sinceId: { type: 'string', format: 'misskey:id' },
|
sinceId: { type: 'string', format: 'misskey:id' },
|
||||||
untilId: { type: 'string', format: 'misskey:id' },
|
untilId: { type: 'string', format: 'misskey:id' },
|
||||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
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(Event, 'event', 'event.noteId = note.id')
|
||||||
.innerJoinAndSelect('note.user', 'user');
|
.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) {
|
if (ps.filters) {
|
||||||
const filters: Record<string, (string | null)[]> = ps.filters;
|
const filters: Record<string, (string | null)[]> = ps.filters;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
<MkSpacer v-else-if="tab === 'event'" :content-max="800">
|
<MkSpacer v-else-if="tab === 'event'" :content-max="800">
|
||||||
<div class="_gaps">
|
<div class="_gaps">
|
||||||
<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>
|
<MkSelect v-model="eventSort" small>
|
||||||
<template #label>{{ 'Sort By' }}</template>
|
<template #label>{{ 'Sort By' }}</template>
|
||||||
<option value="startDate">{{ 'Event Date' }}</option>
|
<option value="startDate">{{ 'Event Date' }}</option>
|
||||||
|
@ -105,7 +108,7 @@ onMounted(() => {
|
||||||
async function search() {
|
async function search() {
|
||||||
const query = searchQuery.toString().trim();
|
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 == null || query === '') && tab !== 'event') return;
|
||||||
|
|
||||||
if (query.startsWith('https://')) {
|
if (query.startsWith('https://')) {
|
||||||
|
@ -149,6 +152,7 @@ async function search() {
|
||||||
endpoint: 'notes/events/search',
|
endpoint: 'notes/events/search',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
params: {
|
params: {
|
||||||
|
query: searchQuery,
|
||||||
sortBy: eventSort,
|
sortBy: eventSort,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue