Don't frequency sort alias results by default

with an option to enable it if desired
This commit is contained in:
DominikDoom
2023-11-29 18:04:50 +01:00
parent a156214a48
commit 4df90f5c95
3 changed files with 9 additions and 2 deletions

View File

@@ -174,10 +174,15 @@ function flatten(obj, roots = [], sep = ".") {
// Calculate biased tag score based on post count and frequent usage
function calculateUsageBias(result, count, uses, lastUseDate) {
// Guard for minimum usage count & last usage date
// Calculate days since last use
const diffTime = Math.abs(Date.now() - (lastUseDate || Date.now()));
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (uses < TAC_CFG.frequencyMinCount || diffDays > TAC_CFG.frequencyMaxAge) {
// Check setting conditions
if (
uses < TAC_CFG.frequencyMinCount ||
diffDays > TAC_CFG.frequencyMaxAge ||
(!TAC_CFG.frequencyIncludeAlias && !result.text.includes(tagword))
) {
uses = 0;
} else if (uses != 0) {
result.usageBias = true;

View File

@@ -226,6 +226,7 @@ async function syncOptions() {
frequencyFunction: opts["tac_frequencyFunction"],
frequencyMinCount: opts["tac_frequencyMinCount"],
frequencyMaxAge: opts["tac_frequencyMaxAge"],
frequencyIncludeAlias: opts["tac_frequencyIncludeAlias"],
// Insertion related settings
replaceUnderscores: opts["tac_replaceUnderscores"],
escapeParentheses: opts["tac_escapeParentheses"],

View File

@@ -423,6 +423,7 @@ def on_ui_settings():
"tac_frequencyFunction": shared.OptionInfo("Logarithmic (weak)", "Function to use for frequency sorting", gr.Dropdown, lambda: {"choices": list(frequency_sort_functions.keys())}).info("; ".join([f'<b>{key}</b>: {val}' for key, val in frequency_sort_functions.items()])),
"tac_frequencyMinCount": shared.OptionInfo(3, "Minimum number of uses for a tag to be considered frequent").info("Tags with less uses than this will not be sorted higher, even if the sorting function would normally result in a higher position."),
"tac_frequencyMaxAge": shared.OptionInfo(30, "Maximum days since last use for a tag to be considered frequent").info("Similar to the above, tags that haven't been used in this many days will not be sorted higher."),
"tac_frequencyIncludeAlias": shared.OptionInfo(False, "Frequency sorting matches aliases for frequent tags").info("Tag frequency will be increased for the main tag even if an alias is used for completion. This option can be used to override the default behavior of alias results being ignored for frequency sorting."),
# Insertion related settings
"tac_replaceUnderscores": shared.OptionInfo(True, "Replace underscores with spaces on insertion"),
"tac_escapeParentheses": shared.OptionInfo(True, "Escape parentheses on insertion"),