Merge lp:~unity-api-team/unity-scope-click/remove_accents_from_search into lp:unity-scope-click

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: dobey
Approved revision: 422
Merged at revision: 422
Proposed branch: lp:~unity-api-team/unity-scope-click/remove_accents_from_search
Merge into: lp:unity-scope-click
Diff against target: 140 lines (+80/-13)
3 files modified
libclickscope/click/interface.cpp (+38/-13)
libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop (+13/-0)
libclickscope/tests/test_interface.cpp (+29/-0)
To merge this branch: bzr merge lp:~unity-api-team/unity-scope-click/remove_accents_from_search
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
dobey (community) Approve
Review via email: mp+286799@code.launchpad.net

Commit message

libclickscope/click/interface.cpp: remove accents and use QString::compare() to find matches

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
420. By Antti Kaijanmäki

Add test.

421. By Antti Kaijanmäki

Accended -> Accented

422. By Antti Kaijanmäki

add second test

Revision history for this message
dobey (dobey) wrote :

Looks ok.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libclickscope/click/interface.cpp'
--- libclickscope/click/interface.cpp 2016-01-04 20:56:17 +0000
+++ libclickscope/click/interface.cpp 2016-03-03 14:30:59 +0000
@@ -31,6 +31,7 @@
31#include <QDir>31#include <QDir>
32#include <QProcess>32#include <QProcess>
33#include <QStandardPaths>33#include <QStandardPaths>
34#include <QString>
34#include <QTimer>35#include <QTimer>
3536
36#include <cstdio>37#include <cstdio>
@@ -56,6 +57,34 @@
5657
57#include <click/click-i18n.h>58#include <click/click-i18n.h>
5859
60namespace {
61
62/* Thanks to
63 * - http://stackoverflow.com/a/14031349
64 * - http://stackoverflow.com/questions/12278448/removing-accents-from-a-qstring
65 */
66QString unaccent(const QString &str)
67{
68 QString tmp = str.normalized(QString::NormalizationForm_KD,
69 QChar::currentUnicodeVersion());
70 QString ret;
71 for (int i = 0, j = tmp.length();
72 i < j;
73 i++) {
74
75 // strip diacritic marks
76 if (tmp.at(i).category() != QChar::Mark_NonSpacing &&
77 tmp.at(i).category() != QChar::Mark_SpacingCombining &&
78 tmp.at(i).category() != QChar::Mark_Enclosing) {
79 ret.append(tmp.at(i));
80 }
81 }
82
83 return ret;
84}
85
86}
87
59namespace click {88namespace click {
6089
61const std::unordered_set<std::string>& nonClickDesktopFiles()90const std::unordered_set<std::string>& nonClickDesktopFiles()
@@ -343,26 +372,22 @@
343 if (search_query.empty()) {372 if (search_query.empty()) {
344 result.push_back(app);373 result.push_back(app);
345 } else {374 } else {
346 std::string lquery = search_query;375 QString lquery = ::unaccent(QString::fromStdString(search_query));
347 std::transform(lquery.begin(), lquery.end(),376
348 lquery.begin(), ::tolower);
349 // Check keywords for the search query as well.377 // Check keywords for the search query as well.
350 for (auto keyword: app.keywords) {378 for (auto kwd: app.keywords) {
351 std::transform(keyword.begin(), keyword.end(),379 QString keyword = ::unaccent(QString::fromStdString(kwd));
352 keyword.begin(), ::tolower);380 if (!keyword.isEmpty()
353 if (!keyword.empty()381 && keyword.contains(lquery, Qt::CaseInsensitive)) {
354 && keyword.find(lquery) != std::string::npos) {
355 result.push_back(app);382 result.push_back(app);
356 return;383 return;
357 }384 }
358 }385 }
359386
360 std::string search_title = app.title;387 QString search_title = ::unaccent(QString::fromStdString(app.title));
361 std::transform(search_title.begin(), search_title.end(),
362 search_title.begin(), ::tolower);
363 // check the app title for the search query.388 // check the app title for the search query.
364 if (!search_title.empty()389 if (!search_title.isEmpty()
365 && search_title.find(lquery) != std::string::npos) {390 && search_title.contains(lquery, Qt::CaseInsensitive)) {
366 result.push_back(app);391 result.push_back(app);
367 }392 }
368 }393 }
369394
=== added file 'libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop'
--- libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop 1970-01-01 00:00:00 +0000
+++ libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop 2016-03-03 14:30:59 +0000
@@ -0,0 +1,13 @@
1[Desktop Entry]
2Version=1.0
3Type=Application
4Terminal=false
5Exec=aa-exec-click -p com.ubuntu.accented_accented_0.5.29 -- qmlscene ./ubuntu-accented-app.qml -I ./plugins
6Icon=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.accented/./accented64.png
7Name=Cámara
8X-Ubuntu-Touch=true
9X-Ubuntu-StageHint=SideStage
10
11Path=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.accented
12X-Ubuntu-Old-Icon=./accented64.png
13X-Ubuntu-Application-ID=com.ubuntu.accented_accented_0.5.29
014
=== modified file 'libclickscope/tests/test_interface.cpp'
--- libclickscope/tests/test_interface.cpp 2016-01-04 20:56:17 +0000
+++ libclickscope/tests/test_interface.cpp 2016-03-03 14:30:59 +0000
@@ -365,6 +365,35 @@
365 EXPECT_EQ(1, results.size());365 EXPECT_EQ(1, results.size());
366}366}
367367
368TEST(ClickInterface, testFindAppAccented)
369{
370 QSharedPointer<click::KeyFileLocator> keyFileLocator(
371 new click::KeyFileLocator(
372 testing::systemApplicationsDirectoryForTesting(),
373 testing::userApplicationsDirectoryForTesting()));
374
375 click::Interface iface(keyFileLocator);
376
377 auto results = iface.find_installed_apps("Cámara");
378
379 EXPECT_EQ(1, results.size());
380}
381
382TEST(ClickInterface, testFindAppAccented2)
383{
384 QSharedPointer<click::KeyFileLocator> keyFileLocator(
385 new click::KeyFileLocator(
386 testing::systemApplicationsDirectoryForTesting(),
387 testing::userApplicationsDirectoryForTesting()));
388
389 click::Interface iface(keyFileLocator);
390
391 auto results = iface.find_installed_apps("Camara");
392
393 EXPECT_EQ(1, results.size());
394}
395
396
368TEST(ClickInterface, testIsIconIdentifier)397TEST(ClickInterface, testIsIconIdentifier)
369{398{
370 EXPECT_TRUE(Interface::is_icon_identifier("contacts-app"));399 EXPECT_TRUE(Interface::is_icon_identifier("contacts-app"));

Subscribers

People subscribed via source and target branches

to all changes: