mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-26 20:06:41 -08:00
Updates to EntrySearcher
* Only search custom named attributes * Search attribute values in addition to keys * Optimize search process
This commit is contained in:
1 parent
5cf50d9fae
commit
d0d1b25e5c
5 files changed
+48
-21
No files matched your search
+28
-15
@@ -32,21 +32,38 @@ QList<Entry*> EntrySearcher::search(const QString& searchString, const Group* ba
|
||||
{
|
||||
Q_ASSERT(baseGroup);
|
||||
|
||||
parseSearchTerms(searchString);
|
||||
return repeat(baseGroup, forceSearch);
|
||||
}
|
||||
|
||||
QList<Entry*> EntrySearcher::repeat(const Group* baseGroup, bool forceSearch)
|
||||
{
|
||||
Q_ASSERT(baseGroup);
|
||||
|
||||
QList<Entry*> results;
|
||||
for (const auto group : baseGroup->groupsRecursive(true)) {
|
||||
if (forceSearch || group->resolveSearchingEnabled()) {
|
||||
results.append(searchEntries(searchString, group->entries()));
|
||||
for (auto* entry : group->entries()) {
|
||||
if (searchEntryImpl(entry)) {
|
||||
results.append(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
QList<Entry*> EntrySearcher::searchEntries(const QString& searchString, const QList<Entry*>& entries)
|
||||
{
|
||||
parseSearchTerms(searchString);
|
||||
return repeatEntries(entries);
|
||||
}
|
||||
|
||||
QList<Entry*> EntrySearcher::repeatEntries(const QList<Entry*>& entries)
|
||||
{
|
||||
QList<Entry*> results;
|
||||
for (Entry* entry : entries) {
|
||||
if (searchEntryImpl(searchString, entry)) {
|
||||
for (auto* entry : entries) {
|
||||
if (searchEntryImpl(entry)) {
|
||||
results.append(entry);
|
||||
}
|
||||
}
|
||||
@@ -63,16 +80,15 @@ bool EntrySearcher::isCaseSensitive()
|
||||
return m_caseSensitive;
|
||||
}
|
||||
|
||||
bool EntrySearcher::searchEntryImpl(const QString& searchString, Entry* entry)
|
||||
bool EntrySearcher::searchEntryImpl(Entry* entry)
|
||||
{
|
||||
// Pre-load in case they are needed
|
||||
auto attributes = QStringList(entry->attributes()->keys());
|
||||
auto attributes_keys = entry->attributes()->customKeys();
|
||||
auto attributes = QStringList(attributes_keys + entry->attributes()->values(attributes_keys));
|
||||
auto attachments = QStringList(entry->attachments()->keys());
|
||||
|
||||
bool found;
|
||||
auto searchTerms = parseSearchTerms(searchString);
|
||||
|
||||
for (const auto& term : searchTerms) {
|
||||
for (const auto& term : m_searchTerms) {
|
||||
switch (term->field) {
|
||||
case Field::Title:
|
||||
found = term->regex.match(entry->resolvePlaceholder(entry->title())).hasMatch();
|
||||
@@ -112,10 +128,9 @@ bool EntrySearcher::searchEntryImpl(const QString& searchString, Entry* entry)
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<QSharedPointer<EntrySearcher::SearchTerm>> EntrySearcher::parseSearchTerms(const QString& searchString)
|
||||
void EntrySearcher::parseSearchTerms(const QString& searchString)
|
||||
{
|
||||
auto terms = QList<QSharedPointer<SearchTerm>>();
|
||||
|
||||
m_searchTerms.clear();
|
||||
auto results = m_termParser.globalMatch(searchString);
|
||||
while (results.hasNext()) {
|
||||
auto result = results.next();
|
||||
@@ -165,8 +180,6 @@ QList<QSharedPointer<EntrySearcher::SearchTerm>> EntrySearcher::parseSearchTerms
|
||||
}
|
||||
}
|
||||
|
||||
terms.append(term);
|
||||
m_searchTerms.append(term);
|
||||
}
|
||||
|
||||
return terms;
|
||||
}
|
||||
Reference in new issue
Block a user