From e0f8f0d722ba04843a6c59d3c1af96361c5b7ca2 Mon Sep 17 00:00:00 2001 From: Patrik Braun Date: Tue, 25 Jul 2017 21:36:28 +0200 Subject: [PATCH] improving mass search handling --- backend/model/sql/SearchManager.ts | 18 ++++++++++++++---- common/entities/SearchResultDTO.ts | 1 + frontend/app/gallery/gallery.component.html | 4 ++++ frontend/app/gallery/gallery.service.ts | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/model/sql/SearchManager.ts b/backend/model/sql/SearchManager.ts index c427e58d..dae956bb 100644 --- a/backend/model/sql/SearchManager.ts +++ b/backend/model/sql/SearchManager.ts @@ -63,14 +63,15 @@ export class SearchManager implements ISearchManager { return this.autoCompleteItemsUnique(result); } - async search(text: string, searchType: SearchTypes) { + async search(text: string, searchType: SearchTypes) { const connection = await SQLConnection.getConnection(); let result: SearchResultDTO = { searchText: text, searchType: searchType, directories: [], - photos: [] + photos: [], + resultOverflow: false }; let query = connection @@ -95,6 +96,7 @@ export class SearchManager implements ISearchManager { query.orWhere('photo.metadata.keywords LIKE :text COLLATE utf8_general_ci', {text: "%" + text + "%"}); } let photos = await query + .setLimit(2001) .getMany(); @@ -106,25 +108,33 @@ export class SearchManager implements ISearchManager { photos[i].metadata.size = JSON.parse(photos[i].metadata.size); } result.photos = photos; + if (result.photos.length > 2000) { + result.resultOverflow = true; + } } result.directories = await connection .getRepository(DirectoryEntity) .createQueryBuilder("dir") .where('dir.name LIKE :text COLLATE utf8_general_ci', {text: "%" + text + "%"}) + .setLimit(201) .getMany(); + if (result.directories.length > 200) { + result.resultOverflow = true; + } return result; } - async instantSearch(text: string) { + async instantSearch(text: string) { const connection = await SQLConnection.getConnection(); let result: SearchResultDTO = { searchText: text, directories: [], - photos: [] + photos: [], + resultOverflow: false }; let photos = await connection diff --git a/common/entities/SearchResultDTO.ts b/common/entities/SearchResultDTO.ts index ac6eb6bd..aa451a77 100644 --- a/common/entities/SearchResultDTO.ts +++ b/common/entities/SearchResultDTO.ts @@ -7,4 +7,5 @@ export interface SearchResultDTO { searchType: SearchTypes; directories: Array; photos: Array; + resultOverflow: boolean; } diff --git a/frontend/app/gallery/gallery.component.html b/frontend/app/gallery/gallery.component.html index b8a1b030..0e7c9c4b 100644 --- a/frontend/app/gallery/gallery.component.html +++ b/frontend/app/gallery/gallery.component.html @@ -31,6 +31,10 @@
+