Changeset View
Changeset View
Standalone View
Standalone View
src/engine/fuzzysearch.h
- This file was added.
1 | #ifndef BALOO_FUZZYSEARCH_H | ||||
---|---|---|---|---|---|
2 | #define BALOO_FUZZYSEARCH_H | ||||
3 | | ||||
4 | #include "engine_export.h" | ||||
5 | | ||||
6 | #include <QString> | ||||
7 | #include <QMap> | ||||
8 | #include <QList> | ||||
9 | #include <QByteArray> | ||||
10 | | ||||
11 | #include <functional> | ||||
12 | | ||||
13 | namespace Baloo { | ||||
14 | class BALOO_ENGINE_EXPORT FuzzyData | ||||
15 | { | ||||
16 | public: | ||||
17 | quint64 id; | ||||
18 | quint8 wid; | ||||
19 | quint8 len; | ||||
20 | | ||||
21 | bool operator==(const FuzzyData &other) const; | ||||
22 | bool operator<(const FuzzyData& other) const; | ||||
23 | }; | ||||
24 | | ||||
25 | class BALOO_ENGINE_EXPORT FuzzyDataList | ||||
26 | { | ||||
27 | public: | ||||
28 | QList<FuzzyData> m_datalist; | ||||
29 | | ||||
30 | QByteArray into_bytes(); | ||||
31 | static FuzzyData from_bytes(); | ||||
32 | | ||||
33 | bool operator==(const FuzzyDataList &other) const; | ||||
34 | }; | ||||
35 | | ||||
36 | using FuzzyFeature = QByteArray; | ||||
37 | | ||||
38 | using FuzzyDataGetter = | ||||
39 | std::function<const FuzzyDataList&(const FuzzyFeature&)>; | ||||
40 | | ||||
41 | class BALOO_ENGINE_EXPORT FuzzySearch | ||||
42 | { | ||||
43 | public: | ||||
44 | FuzzySearch(int tolerance); | ||||
45 | | ||||
46 | static QMap<FuzzyFeature, FuzzyDataList> features(quint64 id, QStringList terms); | ||||
47 | | ||||
48 | static QList<FuzzyFeature> word_to_features(const QString& word); | ||||
49 | | ||||
50 | QList<quint64> search(const QString& query, const FuzzyDataGetter getter); | ||||
51 | | ||||
52 | private: | ||||
53 | int m_tolerance; | ||||
54 | }; | ||||
55 | } | ||||
56 | | ||||
57 | #endif // BALOO_FUZZYSEARCH_H |