1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

improving mass search handling

This commit is contained in:
Patrik Braun 2017-07-25 21:36:28 +02:00
parent 7d146cac87
commit e0f8f0d722
4 changed files with 21 additions and 4 deletions

View File

@ -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 = <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 = <any>JSON.parse(<any>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 = <SearchResultDTO>{
searchText: text,
directories: [],
photos: []
photos: [],
resultOverflow: false
};
let photos = await connection

View File

@ -7,4 +7,5 @@ export interface SearchResultDTO {
searchType: SearchTypes;
directories: Array<DirectoryDTO>;
photos: Array<PhotoDTO>;
resultOverflow: boolean;
}

View File

@ -31,6 +31,10 @@
</div>
<div body class="container" style="width: 100%; padding:0" *ngIf="_galleryService.content.value.searchResult">
<div class="alert alert-info" role="alert"
*ngIf="_galleryService.content.value.searchResult.resultOverflow == true">
Too many results to show. Refine your search.
</div>
<ol class="breadcrumb">
<li class="active">
Searching for:

View File

@ -82,6 +82,8 @@ export class GalleryService {
}
const cw: ContentWrapper = await this.networkService.getJson<ContentWrapper>("/search/" + text, {type: type});
console.log("photos", cw.searchResult.photos.length);
console.log("direcotries", cw.searchResult.directories.length);
this.content.next(cw);
return cw;
}