search gui: allow specifying fields in complex search panel

This commit is contained in:
Jean-Francois Dockes 2011-03-30 18:52:44 +02:00
parent e883c4d04e
commit e61712fc90
4 changed files with 52 additions and 15 deletions

View File

@ -673,6 +673,17 @@ bool RclConfig::getFieldPrefix(const string& _fld, string &pfx)
} }
} }
set<string> RclConfig::getIndexedFields()
{
set<string> flds;
if (m_fields == 0)
return flds;
list<string> sl = m_fields->getNames("prefixes");
flds.insert(sl.begin(), sl.end());
return flds;
}
// Return specialisations of field name for search expansion // Return specialisations of field name for search expansion
// (ie: author->[author, from]) // (ie: author->[author, from])
bool RclConfig::getFieldSpecialisations(const string& fld, bool RclConfig::getFieldSpecialisations(const string& fld,

View File

@ -197,6 +197,7 @@ class RclConfig {
bool getFieldSpecialisationPrefixes(const string& fld, bool getFieldSpecialisationPrefixes(const string& fld,
list<string>& pfxes); list<string>& pfxes);
const set<string>& getStoredFields() {return m_storedFields;} const set<string>& getStoredFields() {return m_storedFields;}
set<string> getIndexedFields();
/** Get canonic name for possible alias */ /** Get canonic name for possible alias */
string fieldCanon(const string& fld); string fieldCanon(const string& fld);
/** Get xattr name to field names translations */ /** Get xattr name to field names translations */

View File

@ -19,6 +19,8 @@ static char rcsid[] = "@(#$Id: searchclause_w.cpp,v 1.4 2006-12-04 06:19:11 dock
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include "recoll.h"
#include "searchclause_w.h" #include "searchclause_w.h"
#include <qvariant.h> #include <qvariant.h>
@ -37,10 +39,15 @@ SearchClauseW::SearchClauseW(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
QHBoxLayout* hLayout = new QHBoxLayout(this); QHBoxLayout* hLayout = new QHBoxLayout(this);
sTpCMB = new QComboBox(this); sTpCMB = new QComboBox(this);
sTpCMB->setEditable(false); sTpCMB->setEditable(false);
hLayout->addWidget(sTpCMB); hLayout->addWidget(sTpCMB);
fldCMB = new QComboBox(this);
fldCMB->setEditable(false);
hLayout->addWidget(fldCMB);
proxSlackSB = new QSpinBox(this); proxSlackSB = new QSpinBox(this);
hLayout->addWidget(proxSlackSB); hLayout->addWidget(proxSlackSB);
@ -77,6 +84,17 @@ void SearchClauseW::languageChange()
sTpCMB->addItem(tr("File name matching"));//5 sTpCMB->addItem(tr("File name matching"));//5
// sTpCMB->insertItem(tr("Complex clause"));//6 // sTpCMB->insertItem(tr("Complex clause"));//6
fldCMB->addItem(tr("In field"));
if (rclconfig) {
set<string> fields = rclconfig->getIndexedFields();
for (set<string>::const_iterator it = fields.begin();
it != fields.end(); it++) {
// Some fields don't make sense here
if (it->compare("filename")) {
fldCMB->addItem(QString::fromUtf8(it->c_str()));
}
}
}
// Ensure that the spinbox will be enabled/disabled depending on // Ensure that the spinbox will be enabled/disabled depending on
// combobox state // combobox state
tpChange(0); tpChange(0);
@ -93,33 +111,34 @@ SearchClauseW::getClause()
{ {
if (wordsLE->text().isEmpty()) if (wordsLE->text().isEmpty())
return 0; return 0;
string field;
if (fldCMB->currentIndex() != 0) {
field = (const char *)fldCMB->currentText().toUtf8();
}
string text = (const char *)wordsLE->text().toUtf8();
switch (sTpCMB->currentIndex()) { switch (sTpCMB->currentIndex()) {
case 0: case 0:
return new SearchDataClauseSimple(SCLT_OR, return new SearchDataClauseSimple(SCLT_OR, text, field);
(const char *)wordsLE->text().toUtf8());
case 1: case 1:
return new SearchDataClauseSimple(SCLT_AND, return new SearchDataClauseSimple(SCLT_AND, text, field);
(const char *)wordsLE->text().toUtf8());
case 2: case 2:
return new SearchDataClauseSimple(SCLT_EXCL, return new SearchDataClauseSimple(SCLT_EXCL, text, field);
(const char *)wordsLE->text().toUtf8());
case 3: case 3:
return new SearchDataClauseDist(SCLT_PHRASE, return new SearchDataClauseDist(SCLT_PHRASE, text,
(const char *)wordsLE->text().toUtf8(), proxSlackSB->value(), field);
proxSlackSB->value());
case 4: case 4:
return new SearchDataClauseDist(SCLT_NEAR, return new SearchDataClauseDist(SCLT_NEAR, text,
(const char *)wordsLE->text().toUtf8(), proxSlackSB->value(), field);
proxSlackSB->value());
case 5: case 5:
return new SearchDataClauseFilename((const char *)wordsLE->text().toUtf8()); return new SearchDataClauseFilename(text);
case 6: case 6:
default: default:
return 0; return 0;
} }
} }
// Handle combobox change: may need to enable/disable the distance spinbox // Handle combobox change: may need to enable/disable the distance
// spinbox and field spec
void SearchClauseW::tpChange(int index) void SearchClauseW::tpChange(int index)
{ {
if (index < 0 || index > 5) if (index < 0 || index > 5)
@ -137,4 +156,9 @@ void SearchClauseW::tpChange(int index)
default: default:
proxSlackSB->close(); proxSlackSB->close();
} }
if (index == 5) {
fldCMB->close();
} else {
fldCMB->show();
}
} }

View File

@ -39,7 +39,8 @@ public:
Rcl::SearchDataClause *getClause(); Rcl::SearchDataClause *getClause();
QComboBox* sTpCMB; QComboBox* sTpCMB;
QSpinBox* proxSlackSB; QComboBox* fldCMB;
QSpinBox* proxSlackSB;
QLineEdit* wordsLE; QLineEdit* wordsLE;
public slots: public slots: