1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Making autocompete item setting more fine tuned #660

This commit is contained in:
Patrik J. Braun 2023-06-22 08:40:48 +02:00
parent 42f17ac7af
commit b1813d7258
2 changed files with 92 additions and 21 deletions

View File

@ -85,7 +85,7 @@ export class SearchManager {
.where('photo.metadata.keywords LIKE :text COLLATE ' + SQL_COLLATE, {
text: '%' + text + '%',
})
.limit(Config.Search.AutoComplete.targetItemsPerCategory * 2)
.limit(Config.Search.AutoComplete.ItemsPerCategory.keyword*2)
.getRawMany()
)
.map(
@ -120,7 +120,7 @@ export class SearchManager {
text: '%' + text + '%',
})
.limit(
Config.Search.AutoComplete.targetItemsPerCategory * 2
Config.Search.AutoComplete.ItemsPerCategory.person*2
)
.orderBy('person.count', 'DESC')
.getRawMany()
@ -161,7 +161,7 @@ export class SearchManager {
.groupBy(
'photo.metadata.positionData.country, photo.metadata.positionData.state, photo.metadata.positionData.city'
)
.limit(Config.Search.AutoComplete.targetItemsPerCategory * 2)
.limit(Config.Search.AutoComplete.ItemsPerCategory.position*2)
.getRawMany()
)
.filter((pm): boolean => !!pm)
@ -199,7 +199,7 @@ export class SearchManager {
text: '%' + text + '%',
})
.limit(
Config.Search.AutoComplete.targetItemsPerCategory * 2
Config.Search.AutoComplete.ItemsPerCategory.file_name*2
)
.getRawMany()
).map((r) => r.name),
@ -223,7 +223,7 @@ export class SearchManager {
{text: '%' + text + '%'}
)
.limit(
Config.Search.AutoComplete.targetItemsPerCategory * 2
Config.Search.AutoComplete.ItemsPerCategory.caption*2
)
.getRawMany()
).map((r) => r.caption),
@ -246,7 +246,7 @@ export class SearchManager {
text: '%' + text + '%',
})
.limit(
Config.Search.AutoComplete.targetItemsPerCategory * 2
Config.Search.AutoComplete.ItemsPerCategory.directory*2
)
.getRawMany()
).map((r) => r.name),
@ -260,13 +260,13 @@ export class SearchManager {
// if not enough items are available, load more from one category
if (
[].concat(...partialResult).length <
Config.Search.AutoComplete.maxItems
Config.Search.AutoComplete.ItemsPerCategory.maxItems
) {
result = [].concat(...partialResult);
} else {
result = [].concat(
...partialResult.map((l) =>
l.slice(0, Config.Search.AutoComplete.targetItemsPerCategory)
l.slice(0, (Config.Search.AutoComplete.ItemsPerCategory as any)[SearchQueryTypes[l[0].type]])
)
);
}

View File

@ -58,6 +58,86 @@ export type TAGS = {
}
};
@SubConfigClass<TAGS>({tags: {client: true}, softReadonly: true})
export class AutoCompleteItemsPerCategoryConfig {
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Maximum items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown at once. If there is not enough items to reach this value, it takes upto double of the individual items.`
})
maxItems: number = 30;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max photo items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per photo category.`
})
file_name: number = 2;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max directory items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per directory category.`
})
directory: number = 2;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max caption items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per caption category.`
})
caption: number = 3;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max position items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per position category.`
})
position: number = 3;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max faces items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per faces category.`
})
person: number = 5;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max keyword items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown per keyword category.`
})
keyword: number = 5;
}
@SubConfigClass<TAGS>({tags: {client: true}, softReadonly: true})
export class AutoCompleteConfig {
@ConfigProperty({
@ -69,8 +149,8 @@ export class AutoCompleteConfig {
description: $localize`Show hints while typing search query.`
})
enabled: boolean = true;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Max items per category`,
@ -78,17 +158,8 @@ export class AutoCompleteConfig {
},
description: $localize`Maximum number autocomplete items shown per category.`
})
targetItemsPerCategory: number = 5;
@ConfigProperty({
type: 'unsignedInt',
tags:
{
name: $localize`Maximum items`,
priority: ConfigPriority.underTheHood
},
description: $localize`Maximum number autocomplete items shown at once.`
})
maxItems: number = 30;
ItemsPerCategory: AutoCompleteItemsPerCategoryConfig = new AutoCompleteItemsPerCategoryConfig();
@ConfigProperty({
type: 'unsignedInt',
tags: