diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index cf721e1e..ab0b9c4a 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -37,7 +37,7 @@ export const meta = { export const paramDef = { type: "object", properties: { - query: { type: "string" }, + query: { type: "string", nullable: true }, sinceId: { type: "string", format: "misskey:id" }, untilId: { type: "string", format: "misskey:id" }, sinceDate: { type: "number", nullable: true }, @@ -69,7 +69,7 @@ export const paramDef = { description: "Either 'chronological' or 'relevancy'", }, }, - required: ["query"], + required: [], } as const; export default define(meta, paramDef, async (ps, me) => { @@ -91,9 +91,11 @@ export default define(meta, paramDef, async (ps, me) => { }); } - query - .andWhere("note.text &@~ :q", { q: `${sqlLikeEscape(ps.query)}` }) - .innerJoinAndSelect("note.user", "user"); + if (ps.query != null) { + query.andWhere("note.text &@~ :q", { q: `${sqlLikeEscape(ps.query)}` }); + } + + query.innerJoinAndSelect("note.user", "user"); // "from: me": search all (public, home, followers, specified) my posts // otherwise: search public indexable posts only diff --git a/packages/client/src/components/MkSearchBox.vue b/packages/client/src/components/MkSearchBox.vue index 40b45270..33ff4217 100644 --- a/packages/client/src/components/MkSearchBox.vue +++ b/packages/client/src/components/MkSearchBox.vue @@ -102,7 +102,7 @@ type searchQuery = } | { action: "search"; - query: string; + query?: string; from?: string; range?: string; withFiles: boolean; @@ -126,9 +126,16 @@ function done(canceled: boolean, result?: searchQuery) { } function search() { + if ( + searchWords.value === "" && + searchUsers.value === "" && + searchRange.value === "" + ) + return; + done(false, { action: "search", - query: searchWords.value, + query: searchWords.value === "" ? undefined : searchWords.value, from: searchUsers.value === "" ? undefined : searchUsers.value, range: searchRange.value === "" ? undefined : searchRange.value, withFiles: searchPostsWithFiles.value, @@ -136,6 +143,8 @@ function search() { } function lookup() { + if (searchWords.value === "") return; + done(false, { action: "lookup", query: searchWords.value, diff --git a/packages/client/src/pages/search.vue b/packages/client/src/pages/search.vue index bb35d2c0..7f226661 100644 --- a/packages/client/src/pages/search.vue +++ b/packages/client/src/pages/search.vue @@ -57,7 +57,7 @@ import moment from "moment"; import { api } from "@/os"; const props = defineProps<{ - query: string; + query?: string; user?: string; host?: string; since?: string; @@ -72,7 +72,7 @@ const notesPagination = { endpoint: "notes/search" as const, limit: 10, params: computed(() => ({ - query: props.query, + query: props.query ?? undefined, userId, host: props.host == null ? undefined : getHost(props.host), sinceDate: diff --git a/packages/client/src/scripts/search.ts b/packages/client/src/scripts/search.ts index e06ac4ad..bd34f8cb 100644 --- a/packages/client/src/scripts/search.ts +++ b/packages/client/src/scripts/search.ts @@ -17,7 +17,7 @@ export async function search() { canceled: false; result: { action: "search"; - query: string; + query?: string; from?: string; range?: string; withFiles: boolean; @@ -69,7 +69,11 @@ export async function search() { } if (result.action === "search") { - let paramString = `q=${encodeURIComponent(result.query)}`; + let paramString = `withFiles=${result.withFiles ? "true" : "false"}`; + + if (result.query != null) { + paramString += `&q=${encodeURIComponent(result.query)}`; + } if (result.from != null) { if (result.from === "me" || result.from.includes("@")) @@ -83,8 +87,6 @@ export async function search() { if (split[1] !== "") paramString += `&until=${split[1]}`; } - paramString += `&withFiles=${result.withFiles ? "true" : "false"}`; - mainRouter.push(`/search?${paramString}`); } }