GUI searching with saved query: restore external indexes from saved query
This commit is contained in:
parent
dbf46f82d5
commit
5f76c2527d
@ -109,6 +109,9 @@ class PrefsPack {
|
||||
// Extra query indexes. This are stored in the history file, not qt prefs
|
||||
vector<string> allExtraDbs;
|
||||
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
|
||||
// but just remember previously entered values
|
||||
QStringList asearchSubdirHist;
|
||||
|
||||
@ -98,16 +98,22 @@ void startManual(const string& helpindex)
|
||||
|
||||
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->rmQueryDb("");
|
||||
for (const auto& dbdir : prefs.activeExtraDbs) {
|
||||
LOGDEB("main: adding [" << dbdir << "]\n");
|
||||
rcldb->addQueryDb(dbdir);
|
||||
auto edbs = &prefs.activeExtraDbs;
|
||||
if (prefs.useTmpActiveExtraDbs) {
|
||||
edbs = &prefs.tmpActiveExtraDbs;
|
||||
}
|
||||
if (!edbs->empty()) {
|
||||
rcldb->setExtraQueryDbs(*edbs);
|
||||
}
|
||||
prefs.useTmpActiveExtraDbs = false;
|
||||
prefs.tmpActiveExtraDbs.clear();
|
||||
|
||||
Rcl::Db::OpenError error;
|
||||
if (!rcldb->isopen() && !rcldb->open(Rcl::Db::DbRO, &error)) {
|
||||
reason = "Could not open database";
|
||||
@ -130,7 +136,7 @@ bool getStemLangs(vector<string>& vlangs)
|
||||
{
|
||||
// Try from db
|
||||
string reason;
|
||||
if (maybeOpenDb(reason)) {
|
||||
if (maybeOpenDb(reason, false)) {
|
||||
vlangs = rcldb->getStemLangs();
|
||||
LOGDEB0("getStemLangs: from index: " << stringsToString(vlangs) <<"\n");
|
||||
return true;
|
||||
@ -385,7 +391,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
maybeOpenDb(reason);
|
||||
maybeOpenDb(reason, false);
|
||||
|
||||
if (op_flags & OPT_w) {
|
||||
mainWindow->showMinimized();
|
||||
|
||||
@ -717,7 +717,7 @@ void RclMain::startSearch(std::shared_ptr<Rcl::SearchData> sdata, bool issimple)
|
||||
string reason;
|
||||
// If indexing is being performed, we reopen the db at each query.
|
||||
if (!maybeOpenDb(reason, m_idxproc != 0)) {
|
||||
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
|
||||
QMessageBox::critical(0, "Recoll", u8s2qs(reason));
|
||||
m_queryActive = false;
|
||||
restable->setEnabled(true);
|
||||
return;
|
||||
@ -952,7 +952,7 @@ void RclMain::showSubDocs(Rcl::Doc doc)
|
||||
{
|
||||
LOGDEB("RclMain::showSubDocs\n");
|
||||
string reason;
|
||||
if (!maybeOpenDb(reason)) {
|
||||
if (!maybeOpenDb(reason, false)) {
|
||||
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
|
||||
return;
|
||||
}
|
||||
@ -1010,7 +1010,7 @@ void RclMain::showDocHistory()
|
||||
curPreview = 0;
|
||||
|
||||
string reason;
|
||||
if (!maybeOpenDb(reason)) {
|
||||
if (!maybeOpenDb(reason, false)) {
|
||||
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -29,8 +29,7 @@
|
||||
// Misc declarations in need of sharing between the UI files
|
||||
|
||||
// Open the database if needed. We now force a close/open by default
|
||||
extern bool maybeOpenDb(std::string &reason, bool force = true,
|
||||
bool *maindberror = 0);
|
||||
extern bool maybeOpenDb(std::string &reason, bool force, bool *maindberror = 0);
|
||||
|
||||
/** Retrieve configured stemming languages */
|
||||
bool getStemLangs(vector<string>& langs);
|
||||
|
||||
@ -142,7 +142,7 @@ void SpellW::doExpand()
|
||||
return;
|
||||
|
||||
string reason;
|
||||
if (!maybeOpenDb(reason)) {
|
||||
if (!maybeOpenDb(reason, false)) {
|
||||
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
|
||||
LOGDEB("SpellW::doExpand: db error: " << (reason) << "\n" );
|
||||
return;
|
||||
|
||||
@ -535,6 +535,20 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
|
||||
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)
|
||||
{
|
||||
string asString;
|
||||
@ -565,14 +579,20 @@ bool SSearch::fromXML(const SSearchDef& fxml)
|
||||
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);
|
||||
if (cur != stored) {
|
||||
QMessageBox::warning(
|
||||
0, "Recoll", tr("External indexes for stored query: ") +
|
||||
QString::fromUtf8(asString.c_str()) +
|
||||
tr(" differ from current preferences (kept)"));
|
||||
0, "Recoll",
|
||||
tr("Could not restore external indexes for stored query:<br> ") +
|
||||
(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) {
|
||||
|
||||
@ -113,6 +113,7 @@ signals:
|
||||
private:
|
||||
int getPartialWord(QString& word);
|
||||
bool startSimpleSearch(const string& q, int maxexp = -1);
|
||||
bool checkExtIndexes(const std::vector<std::string>& dbs);
|
||||
|
||||
RclCompleterModel *m_completermodel{nullptr};
|
||||
QCompleter *m_completer{nullptr};
|
||||
|
||||
@ -1055,23 +1055,6 @@ bool Db::i_close(bool final)
|
||||
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 res = -1;
|
||||
@ -1114,6 +1097,42 @@ int Db::termDocCnt(const string& _term)
|
||||
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)
|
||||
{
|
||||
string dir = _dir;
|
||||
|
||||
@ -338,6 +338,8 @@ public:
|
||||
bool addQueryDb(const string &dir);
|
||||
/** Remove extra database. if dir == "", remove all. */
|
||||
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
|
||||
decide if we can update the index for it */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user