From 28b05f7fb25f522c7ecdd7ca7b534cd8eebb62bc Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 13 Nov 2006 08:58:47 +0000 Subject: [PATCH] make searchdata a more flexible struct --- src/qtgui/advsearch_w.cpp | 58 +++++++++++++++++++++++++++------------ src/qtgui/advsearch_w.h | 5 ++-- src/qtgui/rclmain.ui | 3 +- src/qtgui/rclmain_w.cpp | 19 +++++++------ src/qtgui/rclmain_w.h | 3 +- src/qtgui/reslist.cpp | 12 ++++---- src/qtgui/reslist.h | 8 ++++-- src/qtgui/ssearch_w.cpp | 34 +++++++++++++---------- src/qtgui/ssearch_w.h | 5 ++-- 9 files changed, 91 insertions(+), 56 deletions(-) diff --git a/src/qtgui/advsearch_w.cpp b/src/qtgui/advsearch_w.cpp index cd3486fd..714656d8 100644 --- a/src/qtgui/advsearch_w.cpp +++ b/src/qtgui/advsearch_w.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.4 2006-09-13 08:13:36 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: advsearch_w.cpp,v 1.5 2006-11-13 08:58:47 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -161,7 +161,6 @@ void AdvSearch::addAFiltypPB_clicked() addFiltypPB_clicked(); } - // Activate file type selection void AdvSearch::restrictFtCB_toggled(bool on) { @@ -173,37 +172,60 @@ void AdvSearch::restrictFtCB_toggled(bool on) noFiltypsLB->setEnabled(on); } +using namespace Rcl; void AdvSearch::searchPB_clicked() { - Rcl::AdvSearchData mydata; + RefCntr sdata(new SearchData(SCLT_AND)); + bool hasnotnot = false; + bool hasnot = false; + if (!andWordsLE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseSimple(SCLT_AND, + (const char *)andWordsLE->text().utf8())); + hasnotnot = true; + } + if (!orWordsLE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseSimple(SCLT_OR, + (const char *)orWordsLE->text().utf8())); + hasnotnot = true; + } + if (!orWords1LE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseSimple(SCLT_OR, + (const char *)orWords1LE->text().utf8())); + hasnotnot = true; + } + if (!noWordsLE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseSimple(SCLT_EXCL, + (const char *)noWordsLE->text().utf8())); + hasnot = true; + } + if (!fileNameLE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseFilename( + (const char *)fileNameLE->text().utf8())); + hasnotnot = true; + } + if (!phraseLE->text().isEmpty()) { + sdata->addClause(new SearchDataClauseDist(SCLT_PHRASE, + (const char *)phraseLE->text().utf8(), 0)); + hasnotnot = true; + } - mydata.allwords = string((const char*)(andWordsLE->text().utf8())); - mydata.phrase = string((const char*)(phraseLE->text().utf8())); - mydata.orwords = string((const char*)(orWordsLE->text().utf8())); - mydata.orwords1 = string((const char*)(orWords1LE->text().utf8())); - mydata.nowords = string((const char*)(noWordsLE->text().utf8())); - mydata.filename = string((const char*)(fileNameLE->text().utf8())); - - if (mydata.allwords.empty() && mydata.phrase.empty() && - mydata.orwords.empty() && mydata.orwords1.empty() && - mydata.filename.empty()) { - if (mydata.nowords.empty()) + if (!hasnotnot) { + if (!hasnot) return; QMessageBox::warning(0, "Recoll", tr("Cannot execute pure negative query. " "Please enter common terms in the 'any words' field")); return; } - if (restrictFtCB->isOn() && noFiltypsLB->count() > 0) { for (unsigned int i = 0; i < yesFiltypsLB->count(); i++) { QCString ctext = yesFiltypsLB->item(i)->text().utf8(); - mydata.filetypes.push_back(string((const char *)ctext)); + sdata->m_filetypes.push_back(string((const char *)ctext)); } } if (!subtreeCMB->currentText().isEmpty()) { - mydata.topdir = + sdata->m_topdir = string((const char*)(subtreeCMB->currentText().utf8())); // The listbox is set for no insertion, do it. Have to check // for dups as the internal feature seems to only work for @@ -217,7 +239,7 @@ void AdvSearch::searchPB_clicked() for (int index = 0; index < subtreeCMB->count(); index++) prefs.asearchSubdirHist.push_back(subtreeCMB->text(index)); } - emit startSearch(mydata); + emit startSearch(sdata); } diff --git a/src/qtgui/advsearch_w.h b/src/qtgui/advsearch_w.h index bb9a5bed..b9575588 100644 --- a/src/qtgui/advsearch_w.h +++ b/src/qtgui/advsearch_w.h @@ -1,6 +1,6 @@ #ifndef _ADVSEARCH_W_H_INCLUDED_ #define _ADVSEARCH_W_H_INCLUDED_ -/* @(#$Id: advsearch_w.h,v 1.2 2006-09-13 08:13:36 dockes Exp $ (C) 2005 J.F.Dockes */ +/* @(#$Id: advsearch_w.h,v 1.3 2006-11-13 08:58:47 dockes Exp $ (C) 2005 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 @@ -20,6 +20,7 @@ #include #include #include "advsearch.h" +#include "refcntr.h" #include "recoll.h" #include "searchdata.h" @@ -43,7 +44,7 @@ public slots: virtual void saveFileTypes(); signals: - void startSearch(Rcl::AdvSearchData); + void startSearch(RefCntr); private: virtual void init(); diff --git a/src/qtgui/rclmain.ui b/src/qtgui/rclmain.ui index 8c6cb31a..44d3c1bc 100644 --- a/src/qtgui/rclmain.ui +++ b/src/qtgui/rclmain.ui @@ -135,7 +135,7 @@ 0 0 - startSearch(Rcl::AdvSearchData) + startSearch(RefCntr<Rcl::AdvSearchData>) ResList @@ -292,6 +292,7 @@ ssearch_w.h reslist.h + refcntr.h diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 946c7880..fab66b4b 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.5 2006-11-10 13:32:08 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.6 2006-11-13 08:58:47 dockes Exp $ (C) 2005 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -61,6 +61,7 @@ using std::pair; #include "guiutils.h" #include "reslist.h" #include "transcode.h" +#include "refcntr.h" #include "rclmain_w.h" #include "moc_rclmain_w.cpp" @@ -93,8 +94,8 @@ void RclMain::init() QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize); resList->setFont(nfont); } - connect(sSearch, SIGNAL(startSearch(Rcl::AdvSearchData)), - this, SLOT(startAdvSearch(Rcl::AdvSearchData))); + connect(sSearch, SIGNAL(startSearch(RefCntr)), + this, SLOT(startAdvSearch(RefCntr))); // signals and slots connections connect(sSearch, SIGNAL(clearSearch()), @@ -318,7 +319,7 @@ static string urltolocalpath(string url) // Execute an advanced search query. The parameters normally come from // the advanced search dialog -void RclMain::startAdvSearch(Rcl::AdvSearchData sdata) +void RclMain::startAdvSearch(RefCntr sdata) { LOGDEB(("RclMain::startAdvSearch\n")); // The db may have been closed at the end of indexing @@ -331,7 +332,7 @@ void RclMain::startAdvSearch(Rcl::AdvSearchData sdata) resList->resetSearch(); int qopts = 0; - if (prefs.queryBuildAbstract && !sdata.fileNameOnly()) { + if (prefs.queryBuildAbstract && !sdata->fileNameOnly()) { qopts |= Rcl::Db::QO_BUILD_ABSTRACT; if (prefs.queryReplaceAbstract) qopts |= Rcl::Db::QO_REPLACE_ABSTRACT; @@ -362,8 +363,8 @@ void RclMain::showAdvSearchDialog() asearchform = new AdvSearch(0, tr("Advanced search"), FALSE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu); - connect(asearchform, SIGNAL(startSearch(Rcl::AdvSearchData)), - this, SLOT(startAdvSearch(Rcl::AdvSearchData))); + connect(asearchform, SIGNAL(startSearch(RefCntr)), + this, SLOT(startAdvSearch(RefCntr))); asearchform->show(); } else { // Close and reopen, in hope that makes us visible... @@ -715,8 +716,8 @@ void RclMain::showDocHistory() docsource = new DocSequenceHistory(rcldb, g_dynconf, string(tr("Document history").utf8())); } - Rcl::AdvSearchData sdata; - sdata.description = tr("History data").utf8(); + RefCntr sdata(new Rcl::SearchData(Rcl::SCLT_AND)); + sdata->m_description = tr("History data").utf8(); m_searchId++; resList->setDocSource(docsource, sdata); } diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 88f9a5b6..e8fe9dd9 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -28,6 +28,7 @@ #include "rcldb.h" #include "searchdata.h" #include "spell_w.h" +#include "refcntr.h" #include "rclmain.h" @@ -49,7 +50,7 @@ public slots: virtual void fileExit(); virtual void periodic100(); virtual void startIndexing(); - virtual void startAdvSearch(Rcl::AdvSearchData sdata); + virtual void startAdvSearch(RefCntr sdata); virtual void previewClosed(QWidget * w); virtual void showAdvSearchDialog(); virtual void showSortDialog(); diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 8d1b20d2..020813d0 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: reslist.cpp,v 1.8 2006-11-11 15:30:48 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: reslist.cpp,v 1.9 2006-11-13 08:58:47 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -23,6 +23,7 @@ static char rcsid[] = "@(#$Id: reslist.cpp,v 1.8 2006-11-11 15:30:48 dockes Exp #include "pathut.h" #include "mimehandler.h" #include "plaintorich.h" +#include "refcntr.h" #include "reslist.h" #include "moc_reslist.cpp" @@ -32,7 +33,7 @@ static char rcsid[] = "@(#$Id: reslist.cpp,v 1.8 2006-11-11 15:30:48 dockes Exp #endif ResList::ResList(QWidget* parent, const char* name) - : QTextBrowser(parent, name) + : QTextBrowser(parent, name) { if (!name) setName("resList"); @@ -68,7 +69,8 @@ void ResList::languageChange() } // Acquire new docsource -void ResList::setDocSource(DocSequence *docsource, Rcl::AdvSearchData& sdt) +void ResList::setDocSource(DocSequence *docsource, + RefCntr sdt) { if (m_docsource) delete m_docsource; @@ -607,7 +609,7 @@ void ResList::menuExpand() QString ResList::getDescription() { - return QString::fromUtf8(m_queryData.description.c_str()); + return QString::fromUtf8(m_queryData->m_description.c_str()); } /** Show detailed expansion of a query */ @@ -617,7 +619,7 @@ void ResList::showQueryDetails() // Also limit the total number of lines. const unsigned int ll = 100; const unsigned int maxlines = 50; - string query = m_queryData.description; + string query = m_queryData->m_description; string oq; unsigned int nlines = 0; while (query.length() > 0) { diff --git a/src/qtgui/reslist.h b/src/qtgui/reslist.h index 2210d7c6..b74778a9 100644 --- a/src/qtgui/reslist.h +++ b/src/qtgui/reslist.h @@ -1,6 +1,6 @@ #ifndef _RESLIST_H_INCLUDED_ #define _RESLIST_H_INCLUDED_ -/* @(#$Id: reslist.h,v 1.1 2006-09-22 07:29:34 dockes Exp $ (C) 2005 J.F.Dockes */ +/* @(#$Id: reslist.h,v 1.2 2006-11-13 08:58:47 dockes Exp $ (C) 2005 J.F.Dockes */ #include @@ -14,6 +14,7 @@ using std::list; #include "rcldb.h" #include "docseq.h" #include "searchdata.h" +#include "refcntr.h" class ResList : public QTextBrowser { @@ -29,7 +30,8 @@ class ResList : public QTextBrowser // num is inside the current page or its immediate neighbours. virtual bool getDoc(int docnum, Rcl::Doc &); - virtual void setDocSource(DocSequence *, Rcl::AdvSearchData& qdata); + virtual void setDocSource(DocSequence *, + RefCntr qdata); virtual QPopupMenu *createPopupMenu(const QPoint& pos); virtual QString getDescription(); // Printable actual query performed on db virtual int getResCnt(); // Return total result list size @@ -69,7 +71,7 @@ class ResList : public QTextBrowser private: std::map m_pageParaToReldocnums; - Rcl::AdvSearchData m_queryData; + RefCntr m_queryData; DocSequence *m_docsource; std::vector m_curDocs; int m_winfirst; diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index fb858dd2..ade73c17 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.10 2006-11-04 14:49:46 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.11 2006-11-13 08:58:47 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -31,6 +31,7 @@ static char rcsid[] = "@(#$Id: ssearch_w.cpp,v 1.10 2006-11-04 14:49:46 dockes E #include "guiutils.h" #include "searchdata.h" #include "ssearch_w.h" +#include "refcntr.h" void SSearch::init() { @@ -72,27 +73,30 @@ void SSearch::startSimpleSearch() if (queryText->currentText().length() == 0) return; - Rcl::AdvSearchData sdata; - QCString u8 = queryText->currentText().utf8(); + RefCntr sdata(new Rcl::SearchData(Rcl::SCLT_AND)); + QCString u8 = queryText->currentText().utf8(); switch (searchTypCMB->currentItem()) { case 0: - default: { - QString comp = queryText->currentText(); - // If this is an or and we're set for autophrase and there are - // no quotes in the query, add a phrase search - if (prefs.ssearchAutoPhrase && comp.find('"', 0) == -1) { - comp += QString::fromAscii(" \"") + comp + - QString::fromAscii("\""); - u8 = comp.utf8(); + default: + { + QString comp = queryText->currentText(); + // If this is an or and we're set for autophrase and there are + // no quotes in the query, add a phrase search + if (prefs.ssearchAutoPhrase && comp.find('"', 0) == -1) { + comp += QString::fromAscii(" \"") + comp + + QString::fromAscii("\""); + u8 = comp.utf8(); + } + sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, + (const char *)u8)); } - sdata.orwords = u8; - } break; case 1: - sdata.allwords = u8; + sdata->addClause(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, + (const char *)u8)); break; case 2: - sdata.filename = u8; + sdata->addClause(new Rcl::SearchDataClauseFilename((const char *)u8)); break; } diff --git a/src/qtgui/ssearch_w.h b/src/qtgui/ssearch_w.h index 56268ccd..ffa65012 100644 --- a/src/qtgui/ssearch_w.h +++ b/src/qtgui/ssearch_w.h @@ -1,4 +1,4 @@ -/* @(#$Id: ssearch_w.h,v 1.2 2006-11-04 14:49:46 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: ssearch_w.h,v 1.3 2006-11-13 08:58:47 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 @@ -23,6 +23,7 @@ #include "recoll.h" #include "searchdata.h" #include "ssearchb.h" +#include "refcntr.h" class SSearch : public SSearchBase { @@ -43,7 +44,7 @@ public slots: virtual void startSimpleSearch(); signals: - void startSearch(Rcl::AdvSearchData); + void startSearch(RefCntr); void clearSearch(); private: bool m_escape;