diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index 83be8e65..d031d75d 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -17,7 +17,7 @@ #ifndef _GUIUTILS_H_INCLUDED_ #define _GUIUTILS_H_INCLUDED_ /* - * @(#$Id: guiutils.h,v 1.23 2007-07-12 10:13:37 dockes Exp $ (C) 2005 Jean-Francois Dockes + * @(#$Id: guiutils.h,v 1.24 2007-08-01 10:04:53 dockes Exp $ (C) 2005 Jean-Francois Dockes * jean-francois.dockes@wanadoo.fr * * This program is free software; you can redistribute it and/or modify @@ -144,4 +144,6 @@ extern PrefsPack prefs; /** Read write settings from disk file */ extern void rwSettings(bool dowrite); +extern QString g_stringAllStem, g_stringNoStem; + #endif /* _GUIUTILS_H_INCLUDED_ */ diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 361c9bba2..b322dabf 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.37 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.38 2007-08-01 10:04:53 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -76,6 +76,7 @@ using std::pair; #include "moc_rclmain_w.cpp" extern "C" int XFlush(void *); +QString g_stringAllStem, g_stringNoStem; // Taken from qt designer. Don't know why it's needed. #if (QT_VERSION < 0x040000) @@ -108,10 +109,13 @@ void RclMain::init() } // Stemming language menu - m_idNoStem = preferencesMenu->insertItem(tr("(no stemming)")); - m_stemLangToId[tr("(no stemming)")] = m_idNoStem; + g_stringNoStem = tr("(no stemming)"); + g_stringAllStem = tr("(all languages)"); + m_idNoStem = preferencesMenu->insertItem(g_stringNoStem); + m_stemLangToId[g_stringNoStem] = m_idNoStem; + m_idAllStem = preferencesMenu->insertItem(g_stringAllStem); + m_stemLangToId[g_stringAllStem] = m_idAllStem; - LOGDEB(("idNoStem: %d\n", m_idNoStem)); // Can't get the stemming languages from the db at this stage as // db not open yet (the case where it does not even exist makes // things complicated). So get the languages from the config @@ -124,7 +128,8 @@ void RclMain::init() QMessageBox::warning(0, "Recoll", tr("error retrieving stemming languages")); } - int curid = m_idNoStem, id; // Menu ids are negative integers + int curid = prefs.queryStemLang == "ALL" ? m_idAllStem : m_idNoStem; + int id; for (list::const_iterator it = langs.begin(); it != langs.end(); it++) { QString qlang = QString::fromAscii(it->c_str(), it->length()); @@ -248,6 +253,8 @@ void RclMain::setStemLang(int id) QString lang; if (id == m_idNoStem) { lang = ""; + } else if (id == m_idAllStem) { + lang = "ALL"; } else { lang = preferencesMenu->text(id); } @@ -265,6 +272,8 @@ void RclMain::setStemLang(const QString& lang) int id; if (lang == "") { id = m_idNoStem; + } else if (lang == "ALL") { + id = m_idAllStem; } else { map::iterator it = m_stemLangToId.find(lang); if (it == m_stemLangToId.end()) @@ -399,7 +408,13 @@ void RclMain::startSearch(RefCntr sdata) if (!prefs.queryStemLang.length() == 0) qopts |= Rcl::Db::QO_STEM; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - if (!rcldb->setQuery(sdata, qopts, prefs.queryStemLang.ascii())) { + + string stemLang = (const char *)prefs.queryStemLang.ascii(); + if (stemLang == "ALL") { + rclconfig->getConfParam("indexstemminglanguages", stemLang); + } + + if (!rcldb->setQuery(sdata, qopts, stemLang)) { QMessageBox::warning(0, "Recoll", tr("Cant start query: ") + QString::fromAscii(rcldb->getReason().c_str())); return; diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 2bf40293..3d5549de 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -126,6 +126,7 @@ private: int m_searchId; map m_stemLangToId; int m_idNoStem; + int m_idAllStem; virtual void init(); virtual void previewPrevOrNextInTab(Preview *, int sid, int docnum, diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index d86a4c5b..f36cdd52 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.21 2007-06-12 10:33:48 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.22 2007-08-01 10:04:53 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -215,8 +215,12 @@ void SSearch::completion() // Query database const int max = 100; list strs; - if (!rcldb->termMatch(Rcl::Db::ET_WILD, prefs.queryStemLang.ascii(), - s, strs, max) || strs.size() == 0) { + string stemLang = (const char *)prefs.queryStemLang.ascii(); + if (stemLang == "ALL") { + rclconfig->getConfParam("indexstemminglanguages", stemLang); + } + if (!rcldb->termMatch(Rcl::Db::ET_WILD, stemLang, s, strs, max) || + strs.size() == 0) { QApplication::beep(); return; } diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index 731896f7..de96f17c 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.20 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.21 2007-08-01 10:04:53 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -121,25 +121,22 @@ void UIPrefsDialog::setFromPrefs() // Stemming language combobox stemLangCMB->clear(); - stemLangCMB->insertItem(tr("(no stemming)")); + stemLangCMB->insertItem(g_stringNoStem); + stemLangCMB->insertItem(g_stringAllStem); list langs; if (!getStemLangs(langs)) { QMessageBox::warning(0, "Recoll", tr("error retrieving stemming languages")); } - int i = 0, cur = -1; + int cur = prefs.queryStemLang == "" ? 0 : 1; for (list::const_iterator it = langs.begin(); it != langs.end(); it++) { stemLangCMB-> insertItem(QString::fromAscii(it->c_str(), it->length())); - i++; - if (cur == -1) { - if (!strcmp(prefs.queryStemLang.ascii(), it->c_str())) - cur = i; + if (cur == 0 && !strcmp(prefs.queryStemLang.ascii(), it->c_str())) { + cur = stemLangCMB->count(); } } - if (cur < 0) - cur = 0; stemLangCMB->setCurrentItem(cur); autoPhraseCB->setChecked(prefs.ssearchAutoPhrase); @@ -191,6 +188,8 @@ void UIPrefsDialog::accept() if (stemLangCMB->currentItem() == 0) { prefs.queryStemLang = ""; + } else if (stemLangCMB->currentItem() == 1) { + prefs.queryStemLang = "ALL"; } else { prefs.queryStemLang = stemLangCMB->currentText(); } @@ -238,6 +237,8 @@ void UIPrefsDialog::setStemLang(const QString& lang) int cur = 0; if (lang == "") { cur = 0; + } else if (lang == "ALL") { + cur = 1; } else { for (int i = 1; i < stemLangCMB->count(); i++) { if (lang == stemLangCMB->text(i)) { diff --git a/src/qtgui/uiprefs_w.h b/src/qtgui/uiprefs_w.h index a34dc835..c59d9097 100644 --- a/src/qtgui/uiprefs_w.h +++ b/src/qtgui/uiprefs_w.h @@ -1,4 +1,4 @@ -/* @(#$Id: uiprefs_w.h,v 1.9 2007-08-01 07:55:03 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: uiprefs_w.h,v 1.10 2007-08-01 10:04:53 dockes Exp $ (C) 2006 J.F.Dockes */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ */ #ifndef _UIPREFS_W_H_INCLUDED_ #define _UIPREFS_W_H_INCLUDED_ -/* @(#$Id: uiprefs_w.h,v 1.9 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes */ +/* @(#$Id: uiprefs_w.h,v 1.10 2007-08-01 10:04:53 dockes Exp $ (C) 2005 J.F.Dockes */ #include #include @@ -89,5 +89,4 @@ private: }; - #endif /* _UIPREFS_W_H_INCLUDED_ */ diff --git a/src/rcldb/stemdb.cpp b/src/rcldb/stemdb.cpp index 05539099..927331ff 100644 --- a/src/rcldb/stemdb.cpp +++ b/src/rcldb/stemdb.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.9 2007-05-24 09:35:02 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: stemdb.cpp,v 1.10 2007-08-01 10:04:53 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /** @@ -218,12 +218,13 @@ static string stringlistdisp(const list& sl) } /** - * Expand term to list of all terms which stem to the same term. + * Expand term to list of all terms which stem to the same term, for one + * expansion language */ -bool stemExpand(const std::string& dbdir, - const std::string& lang, - const std::string& term, - list& result) +static bool stemExpandOne(const std::string& dbdir, + const std::string& lang, + const std::string& term, + list& result) { try { Xapian::Stem stemmer(lang); @@ -281,6 +282,30 @@ bool stemExpand(const std::string& dbdir, return true; } + +/** + * Expand term to list of all terms which stem to the same term, add the + * expansion sets for possibly multiple expansion languages + */ +bool stemExpand(const std::string& dbdir, + const std::string& langs, + const std::string& term, + list& result) +{ + + list llangs; + stringToStrings(langs, llangs); + for (list::const_iterator it = llangs.begin(); + it != llangs.end(); it++) { + list oneexp; + stemExpandOne(dbdir, *it, term, oneexp); + result.insert(result.end(), oneexp.begin(), oneexp.end()); + } + result.sort(); + result.unique(); + return true; +} + } } diff --git a/src/rcldb/stemdb.h b/src/rcldb/stemdb.h index 98ae6030..212a63d2 100644 --- a/src/rcldb/stemdb.h +++ b/src/rcldb/stemdb.h @@ -1,6 +1,6 @@ #ifndef _STEMDB_H_INCLUDED_ #define _STEMDB_H_INCLUDED_ -/* @(#$Id: stemdb.h,v 1.3 2006-12-19 12:11:21 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: stemdb.h,v 1.4 2007-08-01 10:04:53 dockes Exp $ (C) 2004 J.F.Dockes */ /// Stem database code /// /// Stem databases list stems and the set of index terms they expand to. They @@ -30,7 +30,7 @@ extern bool createDb(Xapian::Database& xdb, const std::string& dbdir, const std::string& lang); /// Expand term to stem siblings extern bool stemExpand(const std::string& dbdir, - const std::string& lang, + const std::string& langs, const std::string& term, list& result); #ifndef NO_NAMESPACES