fix: update query handling in search API to support filter-only searches
Fixes #284
This commit is contained in:
@@ -5,7 +5,7 @@ import { z } from "zod";
|
||||
import { removeNullOrUndefinedProperties } from "./data.helper";
|
||||
|
||||
interface FindQuery {
|
||||
query: string;
|
||||
query?: string;
|
||||
personIds?: string[];
|
||||
city?: string;
|
||||
country?: string;
|
||||
@@ -27,7 +27,12 @@ const isDateOnly = (value: string) => /^\d{4}-\d{2}-\d{2}$/.test(value);
|
||||
|
||||
|
||||
const responseSchema = z.object({
|
||||
query: z.string().describe("Gist of the query. Remove the details of tags"),
|
||||
query: z
|
||||
.string()
|
||||
.nullish()
|
||||
.describe(
|
||||
"Gist of the query. Remove the details of tags. Omit when the query is only filters (dates, people, places, media type)"
|
||||
),
|
||||
personIds: z
|
||||
.array(z.string())
|
||||
.nullish()
|
||||
@@ -93,6 +98,8 @@ export const parseFindQuery = async (query: string): Promise<FindQuery> => {
|
||||
}),
|
||||
});
|
||||
|
||||
console.log(`[ai] parseFindQuery raw response for "${query}":`, text);
|
||||
|
||||
const parsedResponse = JSON.parse(text) as FindQuery;
|
||||
|
||||
if (parsedResponse.type) {
|
||||
@@ -125,5 +132,7 @@ export const parseFindQuery = async (query: string): Promise<FindQuery> => {
|
||||
parsedResponse.takenBefore = `${parsedResponse.takenBefore}T23:59:59.999Z`;
|
||||
}
|
||||
|
||||
return removeNullOrUndefinedProperties(parsedResponse) as any as FindQuery;
|
||||
const filters = removeNullOrUndefinedProperties(parsedResponse) as any as FindQuery;
|
||||
console.log("[ai] parseFindQuery filters:", filters);
|
||||
return filters;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,11 @@ export default async function search(
|
||||
.where(inArray(person.id, personIds));
|
||||
}
|
||||
|
||||
const url = ENV.IMMICH_URL + "/api/search/smart";
|
||||
// Smart search requires query text; a filter-only search (e.g. "photos
|
||||
// from June 2011") goes to metadata search instead.
|
||||
const url =
|
||||
ENV.IMMICH_URL +
|
||||
(parsedQuery.query ? "/api/search/smart" : "/api/search/metadata");
|
||||
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user