Skip to content

Commit 19d2935

Browse files
committed
fix(search): remove invalid metadata join and correct result unpackin
1 parent a477c36 commit 19d2935

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

backend/app/database/images.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,13 @@ def db_search_images(query: str, tagged: Optional[bool] = None) -> List[dict]:
423423
i.metadata,
424424
i.isTagged,
425425
i.isFavourite,
426-
m.name as tag_name,
427-
md.location as location_name
426+
m.name as tag_name
428427
FROM images i
429428
LEFT JOIN image_classes ic ON i.id = ic.image_id
430429
LEFT JOIN mappings m ON ic.class_id = m.class_id
431-
LEFT JOIN metadata md ON i.id = md.image_id
432430
WHERE (
433431
m.name LIKE ? OR
434-
md.location LIKE ? OR
432+
i.metadata LIKE ? OR
435433
i.path LIKE ?
436434
)
437435
"""
@@ -461,7 +459,6 @@ def db_search_images(query: str, tagged: Optional[bool] = None) -> List[dict]:
461459
is_tagged,
462460
is_favourite,
463461
tag_name,
464-
location_name,
465462
) in results:
466463

467464
if image_id not in images_dict:

frontend/src/components/Navigation/Navbar/Navbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function Navbar() {
3535

3636
return (
3737
<div className="sticky top-0 z-40 flex h-14 w-full items-center justify-between border-b pr-4 backdrop-blur">
38-
3938
{/* Logo */}
4039
<div className="flex w-[256px] items-center justify-center">
4140
<a href="/" className="flex items-center space-x-2">
@@ -64,6 +63,7 @@ export function Navbar() {
6463

6564
{/* Search Input */}
6665
<Input
66+
ref={inputRef}
6767
type="search"
6868
placeholder="Search by tags, faces, or location..."
6969
className="mr-2 flex-1 border-0 bg-neutral-200"
@@ -109,4 +109,4 @@ export function Navbar() {
109109
</div>
110110
</div>
111111
);
112-
}
112+
}

frontend/src/pages/Home/Home.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export const Home = () => {
2626

2727
// GLOBAL SEARCH STATE
2828
const searchState = useSelector((state: RootState) => state.search);
29-
const isTextSearchActive = searchState.active && searchState.type === "text";
30-
const isFaceSearchActive = searchState.active && searchState.type === "face";
31-
const searchQuery = searchState.query || "";
29+
const isTextSearchActive = searchState.active && searchState.type === 'text';
30+
const isFaceSearchActive = searchState.active && searchState.type === 'face';
31+
const searchQuery = searchState.query || '';
3232

3333
// NORMAL FETCH — disabled during search
3434
const { data, isLoading, isSuccess, isError, error } = usePictoQuery({
35-
queryKey: ["images"],
35+
queryKey: ['images'],
3636
queryFn: () => fetchAllImages(),
3737
enabled: !searchState.active,
3838
});
@@ -56,11 +56,11 @@ export const Home = () => {
5656
error,
5757
},
5858
{
59-
loadingMessage: "Loading images",
59+
loadingMessage: 'Loading images',
6060
showSuccess: false,
61-
errorTitle: "Error",
62-
errorMessage: "Failed to load images. Please try again later.",
63-
}
61+
errorTitle: 'Error',
62+
errorMessage: 'Failed to load images. Please try again later.',
63+
},
6464
);
6565

6666
// UPDATE IMAGES BASED ON STATE
@@ -69,7 +69,7 @@ export const Home = () => {
6969
if (isTextSearchActive && searchSuccess) {
7070
const images = (searchData?.data || []) as Image[];
7171
if (!Array.isArray(images)) {
72-
console.error("Invalid search data format");
72+
console.error('Invalid search data format');
7373
return;
7474
}
7575
dispatch(setImages(images));
@@ -81,14 +81,22 @@ export const Home = () => {
8181
const images = (data?.data || []) as Image[];
8282
dispatch(setImages(images));
8383
}
84-
}, [dispatch, searchData, data]);
84+
}, [
85+
dispatch,
86+
searchData,
87+
data,
88+
isTextSearchActive,
89+
searchSuccess,
90+
searchState.active,
91+
isSuccess,
92+
]);
8593

8694
// TITLE
8795
const title = isTextSearchActive
8896
? `Search Results for "${searchQuery}" (${images.length} found)`
8997
: isFaceSearchActive && images.length > 0
90-
? `Face Search Results (${images.length} found)`
91-
: "Image Gallery";
98+
? `Face Search Results (${images.length} found)`
99+
: 'Image Gallery';
92100

93101
return (
94102
<div className="relative flex h-full flex-col pr-6">

0 commit comments

Comments
 (0)