Albert
Loading...
Searching...
No Matches
usagescoring.h
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
4#pragma once
5#include <QHash>
6#include <QString>
7#include <albert/export.h>
8#include <unordered_map>
9#include <vector>
10
11namespace albert
12{
13class RankItem;
14
15
16struct ALBERT_EXPORT ItemKey
17{
18 QString extension_id;
19 QString item_id;
20 bool operator==(const ItemKey&) const = default;
21};
22
23
29class ALBERT_EXPORT UsageScoring
30{
31public:
32
34 double modifiedMatchScore(const ItemKey &key, double match_score) const;
35
37 void modifyMatchScores(const QString &extension_id, std::vector<albert::RankItem> &rank_items) const;
38
41
51
53 std::shared_ptr<const std::unordered_map<ItemKey, double>> usage_scores;
54
55};
56
57}
58
59// Hashing specialization for ItemKey
60template <>
61struct std::hash<albert::ItemKey>
62{
63 // https://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as-the-key#comment39936543_17017281
64 inline std::size_t operator()(const albert::ItemKey& key) const
65 { return (qHash(key.extension_id) ^ (qHash(key.item_id)<< 1)); }
66};
Modifies match scores according to user usage history and preferences.
Definition usagescoring.h:30
double modifiedMatchScore(const ItemKey &key, double match_score) const
Returns the modified match_score for an item identified by key.
double memory_decay
The exponential decay applied to usage scores based on recency.
Definition usagescoring.h:50
std::shared_ptr< const std::unordered_map< ItemKey, double > > usage_scores
The usage scores.
Definition usagescoring.h:53
bool prioritize_perfect_match
If true perfect matches should be prioritized even if their usage score is lower.
Definition usagescoring.h:40
void modifyMatchScores(const QString &extension_id, std::vector< albert::RankItem > &rank_items) const
Modifies the match score of rank_item for an item identified by key in-place.
The Albert namespace.
Definition app.h:55