CLI: Replace locate command with search

* Introduce search CLI command to replace locate command. Search can provide the same functionality but in a more fine-grained fashion

* Replace use of Group::locate in code: Use EntrySearcher in clip cli command best-match option. This removes the matching against group hierarchy of an entry which is kind of nonsense as clip expects exactly one match. Matching against groups can be done using search command.

* Remove obsolete Group::locate method
This commit is contained in:
Robin Ebert
2021-08-03 15:37:47 +02:00
committed by Jonathan White
parent ec81d2bc3f
commit e8f2c9d126
12 changed files with 103 additions and 165 deletions

View File

@@ -18,6 +18,7 @@
#include "Clip.h"
#include "Utils.h"
#include "core/EntrySearcher.h"
#include "core/Group.h"
#include "core/Tools.h"
@@ -78,16 +79,18 @@ int Clip::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
QString entryPath;
if (parser->isSet(Clip::BestMatchOption)) {
QStringList results = database->rootGroup()->locate(args.at(1));
EntrySearcher searcher;
const auto& searchTerm = args.at(1);
const auto results = searcher.search(QString("title:%1").arg(searchTerm), database->rootGroup(), true);
if (results.count() > 1) {
err << QObject::tr("Multiple entries matching:") << endl;
for (const QString& result : asConst(results)) {
err << result << endl;
for (const Entry* result : results) {
err << result->path().prepend('/') << endl;
}
return EXIT_FAILURE;
} else {
entryPath = (results.isEmpty()) ? args.at(1) : results[0];
out << QObject::tr("Used matching entry: %1").arg(entryPath) << endl;
entryPath = (results.isEmpty()) ? searchTerm : results[0]->path().prepend('/');
out << QObject::tr("Using matching entry: %1").arg(entryPath) << endl;
}
} else {
entryPath = args.at(1);