~unity-api-team/hud/test-failures

« back to all changes in this revision

Viewing changes to service/ItemStore.cpp

  • Committer: Charles Kerr
  • Date: 2014-03-17 17:50:58 UTC
  • mfrom: (376.2.5 hud)
  • Revision ID: charles.kerr@canonical.com-20140317175058-7efcri9kck5j3i0q
bzr merge lp:hud

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
using namespace Columbus;
30
30
 
31
31
static const QRegularExpression SINGLE_AMPERSAND("(?<![&])[&](?![&])");
 
32
static const QRegularExpression BAD_CHARACTERS("\\.\\.\\.|…");
32
33
static const QRegularExpression WHITESPACE("\\s+");
33
34
static const QRegularExpression WHITESPACE_OR_SEMICOLON("[;\\s+]");
34
35
 
39
40
        ErrorValues &errorValues(m_matcher.getErrorValues());
40
41
        errorValues.addStandardErrors();
41
42
 
42
 
        connect(m_settings.data(), SIGNAL(changed()), this,
43
 
                                        SLOT(settingChanged()));
 
43
        m_matcher.getIndexWeights().setWeight(Word("context"), 0.5);
 
44
 
 
45
        connect(m_settings.data(), SIGNAL(changed()), this, SLOT(settingChanged()));
44
46
        settingChanged();
45
47
}
46
48
 
72
74
                        continue;
73
75
                }
74
76
 
75
 
                QStringList text(convertActionText(action).split(WHITESPACE));
 
77
                QStringList text(
 
78
                                convertActionText(action).remove(BAD_CHARACTERS).split(
 
79
                                                WHITESPACE));
76
80
 
77
81
                bool isParameterized(action->property("isParameterized").toBool());
78
82
 
89
93
 
90
94
                        WordList command;
91
95
                        for (const QString &word : text) {
92
 
                                command.addWord(Word(word.toStdString()));
 
96
                                command.addWord(Word(word.toUtf8().constData()));
93
97
                        }
94
98
                        document.addText(Word("command"), command);
95
99
 
102
106
                                context = stack;
103
107
                        }
104
108
                        for (const QString &word : context) {
105
 
                                wordList.addWord(Word(word.toStdString()));
 
109
                                wordList.addWord(Word(word.toUtf8().constData()));
106
110
                        }
107
111
                        document.addText(Word("context"), wordList);
108
112
 
150
154
        return result;
151
155
}
152
156
 
153
 
void ItemStore::search(const QString &query, QList<Result> &results) {
 
157
void ItemStore::search(const QString &query,
 
158
                Query::EmptyBehaviour emptyBehaviour, QList<Result> &results) {
154
159
        QStringMatcher stringMatcher(query, Qt::CaseInsensitive);
155
160
 
156
161
        if (query.isEmpty()) {
 
162
                if (emptyBehaviour == Query::EmptyBehaviour::NO_SUGGESTIONS) {
 
163
                        return;
 
164
                }
 
165
 
157
166
                QMap<unsigned int, DocumentID> tempResults;
158
167
 
159
168
                for (auto it(m_items.constBegin()); it != m_items.constEnd(); ++it) {
172
181
                }
173
182
 
174
183
        } else {
 
184
                QString cleanQuery(query);
 
185
                cleanQuery.remove(BAD_CHARACTERS);
 
186
 
175
187
                WordList queryList;
176
 
                for (const QString &word : query.split(WHITESPACE)) {
177
 
                        queryList.addWord(word.toStdString());
 
188
                for (const QString &word : cleanQuery.split(WHITESPACE)) {
 
189
                        queryList.addWord(Word(word.toUtf8().constData()));
178
190
                }
179
191
 
180
 
                MatchResults matchResults(m_matcher.match(queryList));
181
 
 
182
 
                int queryLength(query.length());
183
 
 
184
 
                size_t maxResults = std::min(matchResults.size(), size_t(20));
185
 
 
186
 
                for (size_t i(0); i < maxResults; ++i) {
187
 
                        DocumentID id(matchResults.getDocumentID(i));
188
 
                        double relevancy(matchResults.getRelevancy(i));
189
 
                        addResult(id, stringMatcher, queryLength, relevancy, results);
 
192
                try {
 
193
                        MatchResults matchResults(
 
194
                                        m_matcher.onlineMatch(queryList, Word("command")));
 
195
 
 
196
                        int queryLength(query.length());
 
197
 
 
198
                        size_t maxResults = std::min(matchResults.size(), size_t(20));
 
199
 
 
200
                        for (size_t i(0); i < maxResults; ++i) {
 
201
                                DocumentID id(matchResults.getDocumentID(i));
 
202
                                double relevancy(matchResults.getRelevancy(i));
 
203
                                addResult(id, stringMatcher, queryLength, relevancy, results);
 
204
                        }
 
205
                } catch (std::invalid_argument &e) {
190
206
                }
191
207
        }
192
208