forked from naskya/firefish
feat: allow empty search query
This commit is contained in:
parent
fdb7911d30
commit
65d3190134
4 changed files with 26 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue