mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
Making autocompete finetuning #660
This commit is contained in:
parent
b744c72c31
commit
574de71eb7
@ -85,7 +85,7 @@ export class SearchManager {
|
|||||||
.where('photo.metadata.keywords LIKE :text COLLATE ' + SQL_COLLATE, {
|
.where('photo.metadata.keywords LIKE :text COLLATE ' + SQL_COLLATE, {
|
||||||
text: '%' + text + '%',
|
text: '%' + text + '%',
|
||||||
})
|
})
|
||||||
.limit(Config.Search.AutoComplete.ItemsPerCategory.keyword*2)
|
.limit(Config.Search.AutoComplete.ItemsPerCategory.keyword)
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
)
|
)
|
||||||
.map(
|
.map(
|
||||||
@ -120,7 +120,7 @@ export class SearchManager {
|
|||||||
text: '%' + text + '%',
|
text: '%' + text + '%',
|
||||||
})
|
})
|
||||||
.limit(
|
.limit(
|
||||||
Config.Search.AutoComplete.ItemsPerCategory.person*2
|
Config.Search.AutoComplete.ItemsPerCategory.person
|
||||||
)
|
)
|
||||||
.orderBy('person.count', 'DESC')
|
.orderBy('person.count', 'DESC')
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
@ -161,7 +161,7 @@ export class SearchManager {
|
|||||||
.groupBy(
|
.groupBy(
|
||||||
'photo.metadata.positionData.country, photo.metadata.positionData.state, photo.metadata.positionData.city'
|
'photo.metadata.positionData.country, photo.metadata.positionData.state, photo.metadata.positionData.city'
|
||||||
)
|
)
|
||||||
.limit(Config.Search.AutoComplete.ItemsPerCategory.position*2)
|
.limit(Config.Search.AutoComplete.ItemsPerCategory.position )
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
)
|
)
|
||||||
.filter((pm): boolean => !!pm)
|
.filter((pm): boolean => !!pm)
|
||||||
@ -199,7 +199,7 @@ export class SearchManager {
|
|||||||
text: '%' + text + '%',
|
text: '%' + text + '%',
|
||||||
})
|
})
|
||||||
.limit(
|
.limit(
|
||||||
Config.Search.AutoComplete.ItemsPerCategory.file_name*2
|
Config.Search.AutoComplete.ItemsPerCategory.fileName
|
||||||
)
|
)
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
).map((r) => r.name),
|
).map((r) => r.name),
|
||||||
@ -223,7 +223,7 @@ export class SearchManager {
|
|||||||
{text: '%' + text + '%'}
|
{text: '%' + text + '%'}
|
||||||
)
|
)
|
||||||
.limit(
|
.limit(
|
||||||
Config.Search.AutoComplete.ItemsPerCategory.caption*2
|
Config.Search.AutoComplete.ItemsPerCategory.caption
|
||||||
)
|
)
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
).map((r) => r.caption),
|
).map((r) => r.caption),
|
||||||
@ -246,7 +246,7 @@ export class SearchManager {
|
|||||||
text: '%' + text + '%',
|
text: '%' + text + '%',
|
||||||
})
|
})
|
||||||
.limit(
|
.limit(
|
||||||
Config.Search.AutoComplete.ItemsPerCategory.directory*2
|
Config.Search.AutoComplete.ItemsPerCategory.directory
|
||||||
)
|
)
|
||||||
.getRawMany()
|
.getRawMany()
|
||||||
).map((r) => r.name),
|
).map((r) => r.name),
|
||||||
@ -255,22 +255,23 @@ export class SearchManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: AutoCompleteItem[];
|
const result: AutoCompleteItem[] = [];
|
||||||
|
|
||||||
// if not enough items are available, load more from one category
|
while (result.length < Config.Search.AutoComplete.ItemsPerCategory.maxItems) {
|
||||||
if (
|
let adding = false;
|
||||||
[].concat(...partialResult).length <
|
for (let i = 0; i < partialResult.length; ++i) {
|
||||||
Config.Search.AutoComplete.ItemsPerCategory.maxItems
|
if (partialResult[i].length <= 0) {
|
||||||
) {
|
continue;
|
||||||
result = [].concat(...partialResult);
|
}
|
||||||
} else {
|
result.push(partialResult[i].pop());
|
||||||
result = [].concat(
|
adding = true;
|
||||||
...partialResult.map((l) =>
|
}
|
||||||
l.slice(0, (Config.Search.AutoComplete.ItemsPerCategory as any)[SearchQueryTypes[l[0].type]])
|
if (!adding) {
|
||||||
)
|
break;
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return SearchManager.autoCompleteItemsUnique(result);
|
return SearchManager.autoCompleteItemsUnique(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +721,7 @@ export class SearchManager {
|
|||||||
const relationBottom = tq.negate ? '<=' : '>';
|
const relationBottom = tq.negate ? '<=' : '>';
|
||||||
switch (tq.frequency) {
|
switch (tq.frequency) {
|
||||||
case DatePatternFrequency.every_year:
|
case DatePatternFrequency.every_year:
|
||||||
if(tq.daysLength >= 365){
|
if (tq.daysLength >= 365) {
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
q.where(
|
q.where(
|
||||||
@ -729,7 +730,7 @@ export class SearchManager {
|
|||||||
textParam);
|
textParam);
|
||||||
break;
|
break;
|
||||||
case DatePatternFrequency.every_month:
|
case DatePatternFrequency.every_month:
|
||||||
if(tq.daysLength >=31){
|
if (tq.daysLength >= 31) {
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
q.where(
|
q.where(
|
||||||
@ -738,7 +739,7 @@ export class SearchManager {
|
|||||||
textParam);
|
textParam);
|
||||||
break;
|
break;
|
||||||
case DatePatternFrequency.every_week:
|
case DatePatternFrequency.every_week:
|
||||||
if(tq.daysLength >= 7){
|
if (tq.daysLength >= 7) {
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
q.where(
|
q.where(
|
||||||
|
@ -80,7 +80,7 @@ export class AutoCompleteItemsPerCategoryConfig {
|
|||||||
},
|
},
|
||||||
description: $localize`Maximum number autocomplete items shown per photo category.`
|
description: $localize`Maximum number autocomplete items shown per photo category.`
|
||||||
})
|
})
|
||||||
file_name: number = 2;
|
fileName: number = 2;
|
||||||
|
|
||||||
@ConfigProperty({
|
@ConfigProperty({
|
||||||
type: 'unsignedInt',
|
type: 'unsignedInt',
|
||||||
|
@ -244,27 +244,43 @@ export class AutoCompleteService {
|
|||||||
items: RenderableAutoCompleteItem[]
|
items: RenderableAutoCompleteItem[]
|
||||||
): RenderableAutoCompleteItem[] {
|
): RenderableAutoCompleteItem[] {
|
||||||
const textLC = text.toLowerCase();
|
const textLC = text.toLowerCase();
|
||||||
|
// Source: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
||||||
|
const isStartRgx = new RegExp('(\\s|^)' + textLC.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
||||||
return items.sort((a, b) => {
|
return items.sort((a, b) => {
|
||||||
const aLC = a.text.toLowerCase();
|
const aLC = a.text.toLowerCase();
|
||||||
const bLC = b.text.toLowerCase();
|
const bLC = b.text.toLowerCase();
|
||||||
// prioritize persons higher
|
|
||||||
if (a.type !== b.type) {
|
|
||||||
if (a.type === SearchQueryTypes.person) {
|
|
||||||
return -1;
|
|
||||||
} else if (b.type === SearchQueryTypes.person) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
const basicCompare = () => {
|
||||||
(aLC.startsWith(textLC) && bLC.startsWith(textLC)) ||
|
// prioritize persons higher
|
||||||
(!aLC.startsWith(textLC) && !bLC.startsWith(textLC))
|
if (a.type !== b.type) {
|
||||||
) {
|
if (a.type === SearchQueryTypes.person) {
|
||||||
|
return -1;
|
||||||
|
} else if (b.type === SearchQueryTypes.person) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return aLC.localeCompare(bLC);
|
return aLC.localeCompare(bLC);
|
||||||
|
};
|
||||||
|
|
||||||
|
// both starts with the searched string
|
||||||
|
if (aLC.startsWith(textLC) && bLC.startsWith(textLC)) {
|
||||||
|
return basicCompare();
|
||||||
|
|
||||||
|
// none starts with the searched string
|
||||||
|
} else if (!aLC.startsWith(textLC) && !bLC.startsWith(textLC)) {
|
||||||
|
|
||||||
|
if ((isStartRgx.test(aLC) && isStartRgx.test(bLC)) ||
|
||||||
|
(!isStartRgx.test(aLC) && !isStartRgx.test(bLC))) {
|
||||||
|
return basicCompare();
|
||||||
|
} else if (isStartRgx.test(aLC)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
// one of them starts with the searched string
|
||||||
} else if (aLC.startsWith(textLC)) {
|
} else if (aLC.startsWith(textLC)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return basicCompare();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user