Add uuid search (#9571)

Co-authored-by: lukas <lukas.walter@aceart.de>
This commit is contained in:
aceArt-GmbH 2023-07-04 13:24:10 +02:00 committed by GitHub
parent 0592218fa3
commit 338fe553ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 2 deletions

View File

@ -218,6 +218,9 @@ bool EntrySearcher::searchEntryImpl(const Entry* entry)
} }
found = false; found = false;
break; break;
case Field::Uuid:
found = term.regex.match(entry->uuidToHex()).hasMatch();
break;
default: default:
// Terms without a specific field try to match title, username, url, and notes // Terms without a specific field try to match title, username, url, and notes
found = term.regex.match(entry->resolvePlaceholder(entry->title())).hasMatch() found = term.regex.match(entry->resolvePlaceholder(entry->title())).hasMatch()
@ -253,7 +256,8 @@ void EntrySearcher::parseSearchTerms(const QString& searchString)
{QStringLiteral("url"), Field::Url}, {QStringLiteral("url"), Field::Url},
{QStringLiteral("group"), Field::Group}, {QStringLiteral("group"), Field::Group},
{QStringLiteral("tag"), Field::Tag}, {QStringLiteral("tag"), Field::Tag},
{QStringLiteral("is"), Field::Is}}; {QStringLiteral("is"), Field::Is},
{QStringLiteral("uuid"), Field::Uuid}};
// Group 1 = modifiers, Group 2 = field, Group 3 = quoted string, Group 4 = unquoted string // Group 1 = modifiers, Group 2 = field, Group 3 = quoted string, Group 4 = unquoted string
static QRegularExpression termParser(R"re(([-!*+]+)?(?:(\w*):)?(?:(?=")"((?:[^"\\]|\\.)*)"|([^ ]*))( |$))re"); static QRegularExpression termParser(R"re(([-!*+]+)?(?:(\w*):)?(?:(?=")"((?:[^"\\]|\\.)*)"|([^ ]*))( |$))re");

View File

@ -40,7 +40,8 @@ public:
AttributeValue, AttributeValue,
Group, Group,
Tag, Tag,
Is Is,
Uuid
}; };
struct SearchTerm struct SearchTerm

View File

@ -214,6 +214,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string notr="true">uuid</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">

View File

@ -17,6 +17,7 @@
#include "TestEntrySearcher.h" #include "TestEntrySearcher.h"
#include "core/Group.h" #include "core/Group.h"
#include "core/Tools.h"
#include <QTest> #include <QTest>
@ -372,3 +373,24 @@ void TestEntrySearcher::testSkipProtected()
m_entrySearcher.search("_testAttribute:testE1 _testProtected:apple _testAttribute:testE2", m_rootGroup); m_entrySearcher.search("_testAttribute:testE1 _testProtected:apple _testAttribute:testE2", m_rootGroup);
QCOMPARE(m_searchResult, {}); QCOMPARE(m_searchResult, {});
} }
void TestEntrySearcher::testUUIDSearch()
{
auto entry1 = new Entry();
entry1->setGroup(m_rootGroup);
entry1->setTitle("testTitle");
auto uuid1 = QUuid::createUuid();
entry1->setUuid(uuid1);
auto entry2 = new Entry();
entry2->setGroup(m_rootGroup);
entry2->setTitle("testTitle2");
auto uuid2 = QUuid::createUuid();
entry2->setUuid(uuid2);
m_searchResult = m_entrySearcher.search("uuid:", m_rootGroup);
QCOMPARE(m_searchResult.count(), 2);
m_searchResult = m_entrySearcher.search("uuid:" + Tools::uuidToHex(uuid1), m_rootGroup);
QCOMPARE(m_searchResult.count(), 1);
}

View File

@ -38,6 +38,7 @@ private slots:
void testCustomAttributesAreSearched(); void testCustomAttributesAreSearched();
void testGroup(); void testGroup();
void testSkipProtected(); void testSkipProtected();
void testUUIDSearch();
private: private:
Group* m_rootGroup; Group* m_rootGroup;