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