add search object logic

This commit is contained in:
Abhinav 2022-02-22 13:50:48 +05:30
parent 571cee8fca
commit 358a249c62
5 changed files with 43 additions and 4 deletions

View file

@ -192,6 +192,13 @@ const PhotoFrame = ({
return false;
}
if (
search.thing &&
search.thing.files.indexOf(item.id) === -1
) {
return false;
}
if (isSharedFile(item) && !isSharedCollection) {
return false;
}

View file

@ -12,6 +12,7 @@ import {
searchCollection,
searchFiles,
searchLocation,
searchObject,
} from 'services/searchService';
import { getFormattedDate } from 'utils/search';
import constants from 'utils/strings/constants';
@ -32,7 +33,7 @@ import { FILE_TYPE } from 'constants/file';
import { GalleryContext } from 'pages/gallery';
import { AppContext } from 'pages/_app';
import { Col } from 'react-bootstrap';
import { Person } from 'types/machineLearning';
import { Person, Thing } from 'types/machineLearning';
import { IndexStatus } from 'types/machineLearning/ui';
import { PeopleList } from './MachineLearning/PeopleList';
@ -202,6 +203,18 @@ export default function SearchBar(props: Props) {
} as Suggestion)
)
);
const objectResults = await searchObject(searchPhrase);
options.push(
...objectResults.map(
(searchResult) =>
({
type: SuggestionType.OBJECT,
value: searchResult,
label: searchResult.class,
} as Suggestion)
)
);
return options;
};
@ -238,6 +251,10 @@ export default function SearchBar(props: Props) {
props.setSearch({ person: selectedOption.value as Person });
props.setOpen(true);
break;
case SuggestionType.OBJECT:
props.setSearch({ thing: selectedOption.value as Thing });
props.setOpen(true);
break;
}
};
const resetSearch = () => {

View file

@ -16,6 +16,8 @@ import {
Suggestion,
SuggestionType,
} from 'types/search';
import ObjectService from './machineLearning/objectService';
import { Thing } from 'types/machineLearning';
const ENDPOINT = getEndpoint();
@ -171,3 +173,14 @@ export function searchFiles(searchPhrase: string, files: EnteFile[]) {
.filter(({ title }) => title.toLowerCase().includes(searchPhrase))
.slice(0, 4);
}
export async function searchObject(searchPhrase: string) {
const clusteredObjects = await ObjectService.getClusteredObjects();
const matches = [] as Thing[];
for (const [key, value] of clusteredObjects.entries()) {
if (key.toLocaleLowerCase().includes(searchPhrase)) {
matches.push({ class: key, files: value });
}
}
return matches;
}

View file

@ -1,7 +1,7 @@
import { SetDialogMessage } from 'components/MessageDialog';
import { Collection } from 'types/collection';
import { EnteFile } from 'types/file';
import { Person } from 'types/machineLearning';
import { Person, Thing } from 'types/machineLearning';
import { DateValue, Bbox } from 'types/search';
export type SelectedState = {
@ -19,6 +19,7 @@ export type Search = {
location?: Bbox;
fileIndex?: number;
person?: Person;
thing?: Thing;
};
export interface SearchStats {
resultCount: number;

View file

@ -1,4 +1,4 @@
import { Person } from 'types/machineLearning';
import { Person, Thing } from 'types/machineLearning';
import { IndexStatus } from 'types/machineLearning/ui';
export type Bbox = [number, number, number, number];
@ -16,6 +16,7 @@ export enum SuggestionType {
VIDEO,
PERSON,
INDEX_STATUS,
OBJECT,
}
export interface DateValue {
@ -27,6 +28,6 @@ export interface DateValue {
export interface Suggestion {
type: SuggestionType;
label: string;
value: Bbox | DateValue | number | Person | IndexStatus;
value: Bbox | DateValue | number | Person | IndexStatus | Thing;
hide?: boolean;
}