make searchdata a more flexible struct

This commit is contained in:
dockes 2006-11-13 08:58:47 +00:00
parent cdbf026738
commit 28b05f7fb2
9 changed files with 91 additions and 56 deletions

View File

@ -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<SearchData> 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);
}

View File

@ -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 <qvariant.h>
#include <qdialog.h>
#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<Rcl::SearchData>);
private:
virtual void init();

View File

@ -135,7 +135,7 @@
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<signal>startSearch(Rcl::AdvSearchData)</signal>
<signal>startSearch(RefCntr&lt;Rcl::AdvSearchData&gt;)</signal>
</customwidget>
<customwidget>
<class>ResList</class>
@ -292,6 +292,7 @@
<includes>
<include location="local" impldecl="in declaration">ssearch_w.h</include>
<include location="local" impldecl="in declaration">reslist.h</include>
<include location="local" impldecl="in declaration">refcntr.h</include>
</includes>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>

View File

@ -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<Rcl::SearchData>)),
this, SLOT(startAdvSearch(RefCntr<Rcl::SearchData>)));
// 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<Rcl::SearchData> 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<Rcl::SearchData>)),
this, SLOT(startAdvSearch(RefCntr<Rcl::SearchData>)));
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<Rcl::SearchData> sdata(new Rcl::SearchData(Rcl::SCLT_AND));
sdata->m_description = tr("History data").utf8();
m_searchId++;
resList->setDocSource(docsource, sdata);
}

View File

@ -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<Rcl::SearchData> sdata);
virtual void previewClosed(QWidget * w);
virtual void showAdvSearchDialog();
virtual void showSortDialog();

View File

@ -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 <time.h>
@ -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<Rcl::SearchData> 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) {

View File

@ -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 <list>
@ -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<Rcl::SearchData> 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<int,int> m_pageParaToReldocnums;
Rcl::AdvSearchData m_queryData;
RefCntr<Rcl::SearchData> m_queryData;
DocSequence *m_docsource;
std::vector<Rcl::Doc> m_curDocs;
int m_winfirst;

View File

@ -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<Rcl::SearchData> 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;
}

View File

@ -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<Rcl::SearchData>);
void clearSearch();
private:
bool m_escape;