GUI searching with saved query: restore external indexes from saved query

This commit is contained in:
Jean-Francois Dockes 2020-05-19 14:20:21 +02:00
parent dbf46f82d5
commit 5f76c2527d
9 changed files with 250 additions and 200 deletions

View File

@ -109,6 +109,9 @@ class PrefsPack {
// Extra query indexes. This are stored in the history file, not qt prefs // Extra query indexes. This are stored in the history file, not qt prefs
vector<string> allExtraDbs; vector<string> allExtraDbs;
vector<string> activeExtraDbs; vector<string> activeExtraDbs;
// Temporary value while we run a saved query. Erased right after use.
bool useTmpActiveExtraDbs{false};
vector<string> tmpActiveExtraDbs;
// Advanced search subdir restriction: we don't activate the last value // Advanced search subdir restriction: we don't activate the last value
// but just remember previously entered values // but just remember previously entered values
QStringList asearchSubdirHist; QStringList asearchSubdirHist;

View File

@ -98,16 +98,22 @@ void startManual(const string& helpindex)
bool maybeOpenDb(string &reason, bool force, bool *maindberror) bool maybeOpenDb(string &reason, bool force, bool *maindberror)
{ {
LOGDEB2("maybeOpenDb: force " << force << "\n"); LOGDEB1("maybeOpenDb: force " << force << "\n");
if (force) { if (force || nullptr == rcldb) {
rcldb = std::shared_ptr<Rcl::Db>(new Rcl::Db(theconfig)); rcldb = std::shared_ptr<Rcl::Db>(new Rcl::Db(theconfig));
} }
rcldb->rmQueryDb(""); rcldb->rmQueryDb("");
for (const auto& dbdir : prefs.activeExtraDbs) { auto edbs = &prefs.activeExtraDbs;
LOGDEB("main: adding [" << dbdir << "]\n"); if (prefs.useTmpActiveExtraDbs) {
rcldb->addQueryDb(dbdir); edbs = &prefs.tmpActiveExtraDbs;
} }
if (!edbs->empty()) {
rcldb->setExtraQueryDbs(*edbs);
}
prefs.useTmpActiveExtraDbs = false;
prefs.tmpActiveExtraDbs.clear();
Rcl::Db::OpenError error; Rcl::Db::OpenError error;
if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) { if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) {
reason = "Could not open database"; reason = "Could not open database";
@ -130,7 +136,7 @@ bool getStemLangs(vector<string>& vlangs)
{ {
// Try from db // Try from db
string reason; string reason;
if (maybeOpenDb(reason)) { if (maybeOpenDb(reason, false)) {
vlangs = rcldb->getStemLangs(); vlangs = rcldb->getStemLangs();
LOGDEB0("getStemLangs: from index: " << stringsToString(vlangs) <<"\n"); LOGDEB0("getStemLangs: from index: " << stringsToString(vlangs) <<"\n");
return true; return true;
@ -385,7 +391,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
maybeOpenDb(reason); maybeOpenDb(reason, false);
if (op_flags & OPT_w) { if (op_flags & OPT_w) {
mainWindow->showMinimized(); mainWindow->showMinimized();

View File

@ -717,7 +717,7 @@ void RclMain::startSearch(std::shared_ptr<Rcl::SearchData> sdata, bool issimple)
string reason; string reason;
// If indexing is being performed, we reopen the db at each query. // If indexing is being performed, we reopen the db at each query.
if (!maybeOpenDb(reason, m_idxproc != 0)) { if (!maybeOpenDb(reason, m_idxproc != 0)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str())); QMessageBox::critical(0, "Recoll", u8s2qs(reason));
m_queryActive = false; m_queryActive = false;
restable->setEnabled(true); restable->setEnabled(true);
return; return;
@ -952,7 +952,7 @@ void RclMain::showSubDocs(Rcl::Doc doc)
{ {
LOGDEB("RclMain::showSubDocs\n"); LOGDEB("RclMain::showSubDocs\n");
string reason; string reason;
if (!maybeOpenDb(reason)) { if (!maybeOpenDb(reason, false)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str())); QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
return; return;
} }
@ -1010,7 +1010,7 @@ void RclMain::showDocHistory()
curPreview = 0; curPreview = 0;
string reason; string reason;
if (!maybeOpenDb(reason)) { if (!maybeOpenDb(reason, false)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str())); QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
return; return;
} }

View File

@ -29,8 +29,7 @@
// Misc declarations in need of sharing between the UI files // Misc declarations in need of sharing between the UI files
// Open the database if needed. We now force a close/open by default // Open the database if needed. We now force a close/open by default
extern bool maybeOpenDb(std::string &reason, bool force = true, extern bool maybeOpenDb(std::string &reason, bool force, bool *maindberror = 0);
bool *maindberror = 0);
/** Retrieve configured stemming languages */ /** Retrieve configured stemming languages */
bool getStemLangs(vector<string>& langs); bool getStemLangs(vector<string>& langs);

View File

@ -142,7 +142,7 @@ void SpellW::doExpand()
return; return;
string reason; string reason;
if (!maybeOpenDb(reason)) { if (!maybeOpenDb(reason, false)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str())); QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
LOGDEB("SpellW::doExpand: db error: " << (reason) << "\n" ); LOGDEB("SpellW::doExpand: db error: " << (reason) << "\n" );
return; return;

View File

@ -535,6 +535,20 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
return true; return true;
} }
bool SSearch::checkExtIndexes(const std::vector<std::string>& dbs)
{
std::string reason;
if (!maybeOpenDb(reason, false)) {
QMessageBox::critical(0, "Recoll", tr("Can't open index") +
u8s2qs(reason));
return false;
}
if (!rcldb->setExtraQueryDbs(dbs)) {
return false;
}
return true;
}
bool SSearch::fromXML(const SSearchDef& fxml) bool SSearch::fromXML(const SSearchDef& fxml)
{ {
string asString; string asString;
@ -565,14 +579,20 @@ bool SSearch::fromXML(const SSearchDef& fxml)
tr(" differ from current preferences (kept)")); tr(" differ from current preferences (kept)"));
} }
cur = set<string>(prefs.activeExtraDbs.begin(), prefs.activeExtraDbs.end());
stored = set<string>(fxml.extindexes.begin(), fxml.extindexes.end()); if (!checkExtIndexes(fxml.extindexes)) {
std::string asString;
stringsToString(fxml.extindexes, asString); stringsToString(fxml.extindexes, asString);
if (cur != stored) {
QMessageBox::warning( QMessageBox::warning(
0, "Recoll", tr("External indexes for stored query: ") + 0, "Recoll",
QString::fromUtf8(asString.c_str()) + tr("Could not restore external indexes for stored query:<br> ") +
tr(" differ from current preferences (kept)")); (rcldb ? u8s2qs(rcldb->getReason()) : tr("???")) + QString("<br>") +
tr("Using current preferences."));
string s;
maybeOpenDb(s, true);
} else {
prefs.useTmpActiveExtraDbs = true;
prefs.tmpActiveExtraDbs = fxml.extindexes;
} }
if (prefs.ssearchAutoPhrase && !fxml.autophrase) { if (prefs.ssearchAutoPhrase && !fxml.autophrase) {

View File

@ -113,6 +113,7 @@ signals:
private: private:
int getPartialWord(QString& word); int getPartialWord(QString& word);
bool startSimpleSearch(const string& q, int maxexp = -1); bool startSimpleSearch(const string& q, int maxexp = -1);
bool checkExtIndexes(const std::vector<std::string>& dbs);
RclCompleterModel *m_completermodel{nullptr}; RclCompleterModel *m_completermodel{nullptr};
QCompleter *m_completer{nullptr}; QCompleter *m_completer{nullptr};

View File

@ -1055,23 +1055,6 @@ bool Db::i_close(bool final)
return false; return false;
} }
// Reopen the db with a changed list of additional dbs
bool Db::adjustdbs()
{
if (m_mode != DbRO) {
LOGERR("Db::adjustdbs: mode not RO\n");
return false;
}
if (m_ndb && m_ndb->m_isopen) {
if (!close())
return false;
if (!open(m_mode)) {
return false;
}
}
return true;
}
int Db::docCnt() int Db::docCnt()
{ {
int res = -1; int res = -1;
@ -1114,6 +1097,42 @@ int Db::termDocCnt(const string& _term)
return res; return res;
} }
// Reopen the db with a changed list of additional dbs
bool Db::adjustdbs()
{
if (m_mode != DbRO) {
LOGERR("Db::adjustdbs: mode not RO\n");
return false;
}
if (m_ndb && m_ndb->m_isopen) {
if (!close())
return false;
if (!open(m_mode)) {
return false;
}
}
return true;
}
// Set the extra indexes to the input list.
bool Db::setExtraQueryDbs(const std::vector<std::string>& dbs)
{
LOGDEB0("Db::setExtraQueryDbs: ndb " << m_ndb << " iswritable " <<
((m_ndb)?m_ndb->m_iswritable:0) << " dbs [" <<
stringsToString(dbs) << "]\n");
if (!m_ndb) {
return false;
}
if (m_ndb->m_iswritable) {
return false;
}
m_extraDbs.clear();
for (const auto& dir : dbs) {
m_extraDbs.push_back(path_canon(dir));
}
return adjustdbs();
}
bool Db::addQueryDb(const string &_dir) bool Db::addQueryDb(const string &_dir)
{ {
string dir = _dir; string dir = _dir;

View File

@ -338,6 +338,8 @@ public:
bool addQueryDb(const string &dir); bool addQueryDb(const string &dir);
/** Remove extra database. if dir == "", remove all. */ /** Remove extra database. if dir == "", remove all. */
bool rmQueryDb(const string &dir); bool rmQueryDb(const string &dir);
/** Set the extra indexes to the input list. */
bool setExtraQueryDbs(const std::vector<std::string>& dbs);
/** Check if document comes from the main index (this is used to /** Check if document comes from the main index (this is used to
decide if we can update the index for it */ decide if we can update the index for it */