(person);
const [merging, setMerging] = useState(false);
+ const [threshold, setThreshold] = useState(0.5);
const { toast } = useToast();
const selectedIds = useMemo(
@@ -89,7 +90,7 @@ export function PersonMergeDropdown({
};
const fetchSuggestions = () => {
- return listSimilarFaces(person.id)
+ return listSimilarFaces(person.id, threshold)
.then(setSimilarPeople)
.catch(() => {
toast({
@@ -161,6 +162,13 @@ export function PersonMergeDropdown({
setSelectedPeople(newSelected);
};
+ useEffect(() => {
+ if (open) {
+ setSimilarLoading(true);
+ fetchSuggestions();
+ }
+ }, [threshold, open]);
+
useEffect(() => {
if (open && !similarPeople.length) fetchSuggestions();
}, [open, person.id, similarPeople]);
@@ -279,6 +287,21 @@ export function PersonMergeDropdown({
handleSearch(e.target.value);
}}
/>
+
+
+ setThreshold(parseFloat(e.target.value))}
+ placeholder="Threshold (0 to 1)"
+ className="mt-2"
+ />
+
{selectedPeople.length > 0 ? (
diff --git a/src/handlers/api/people.handler.ts b/src/handlers/api/people.handler.ts
index 5c42d5a..7e85646 100644
--- a/src/handlers/api/people.handler.ts
+++ b/src/handlers/api/people.handler.ts
@@ -39,6 +39,7 @@ export const mergePerson = (id: string, targetIds: string[]) => {
return API.post(MERGE_PERSON_PATH(id), { ids: targetIds })
}
-export const listSimilarFaces = (id: string) => {
- return API.get(SIMILAR_FACES_PATH(id)).then((response) => response.map((person: any) => cleanUpPerson(person, true)));
+export const listSimilarFaces = (id: string, threshold: number) => {
+ return API.get(SIMILAR_FACES_PATH(id), { threshold: threshold })
+ .then((response) => response.map((person: any) => cleanUpPerson(person, true)));
}
\ No newline at end of file
diff --git a/src/pages/api/people/[id]/similar-faces.ts b/src/pages/api/people/[id]/similar-faces.ts
index e1466b7..32741d3 100644
--- a/src/pages/api/people/[id]/similar-faces.ts
+++ b/src/pages/api/people/[id]/similar-faces.ts
@@ -18,6 +18,7 @@ interface IQuery {
minimumAssetCount: number;
sort: ISortField;
sortOrder: "asc" | "desc";
+ threshold?: number;
}
export default async function handler(
req: NextApiRequest,
@@ -26,9 +27,10 @@ export default async function handler(
try {
const {
id,
+ threshold = 0.5,
} = req.query as any as IQuery;
- const currentUser = await getCurrentUser(req);
+ const currentUser = await getCurrentUser(req);
const personRecords = await db
.select()
.from(person)
@@ -92,7 +94,7 @@ export default async function handler(
and(
ne(person.id, id),
eq(person.ownerId, currentUser.id),
- gt(similarity, 0.5)
+ gt(similarity, threshold)
)
)
.limit(12);