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; return false;
} }
if (
search.thing &&
search.thing.files.indexOf(item.id) === -1
) {
return false;
}
if (isSharedFile(item) && !isSharedCollection) { if (isSharedFile(item) && !isSharedCollection) {
return false; return false;
} }

View file

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

View file

@ -16,6 +16,8 @@ import {
Suggestion, Suggestion,
SuggestionType, SuggestionType,
} from 'types/search'; } from 'types/search';
import ObjectService from './machineLearning/objectService';
import { Thing } from 'types/machineLearning';
const ENDPOINT = getEndpoint(); const ENDPOINT = getEndpoint();
@ -171,3 +173,14 @@ export function searchFiles(searchPhrase: string, files: EnteFile[]) {
.filter(({ title }) => title.toLowerCase().includes(searchPhrase)) .filter(({ title }) => title.toLowerCase().includes(searchPhrase))
.slice(0, 4); .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 { SetDialogMessage } from 'components/MessageDialog';
import { Collection } from 'types/collection'; import { Collection } from 'types/collection';
import { EnteFile } from 'types/file'; import { EnteFile } from 'types/file';
import { Person } from 'types/machineLearning'; import { Person, Thing } from 'types/machineLearning';
import { DateValue, Bbox } from 'types/search'; import { DateValue, Bbox } from 'types/search';
export type SelectedState = { export type SelectedState = {
@ -19,6 +19,7 @@ export type Search = {
location?: Bbox; location?: Bbox;
fileIndex?: number; fileIndex?: number;
person?: Person; person?: Person;
thing?: Thing;
}; };
export interface SearchStats { export interface SearchStats {
resultCount: number; 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'; import { IndexStatus } from 'types/machineLearning/ui';
export type Bbox = [number, number, number, number]; export type Bbox = [number, number, number, number];
@ -16,6 +16,7 @@ export enum SuggestionType {
VIDEO, VIDEO,
PERSON, PERSON,
INDEX_STATUS, INDEX_STATUS,
OBJECT,
} }
export interface DateValue { export interface DateValue {
@ -27,6 +28,6 @@ export interface DateValue {
export interface Suggestion { export interface Suggestion {
type: SuggestionType; type: SuggestionType;
label: string; label: string;
value: Bbox | DateValue | number | Person | IndexStatus; value: Bbox | DateValue | number | Person | IndexStatus | Thing;
hide?: boolean; hide?: boolean;
} }