move sort params from searchdata to rclquery
This commit is contained in:
parent
5d29d7504e
commit
6d48df7a91
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: pyrecoll.cpp,v 1.13 2008-09-16 10:19:24 dockes Exp $ (C) 2007 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: pyrecoll.cpp,v 1.14 2008-09-29 06:58:25 dockes Exp $ (C) 2007 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
|
||||
@ -86,8 +86,8 @@ SearchData_init(recoll_SearchDataObject *self, PyObject *args, PyObject *kwargs)
|
||||
|
||||
/* Note: addclause necessite And/Or vient du fait que le string peut avoir
|
||||
plusieurs mots. A transferer dans l'i/f Python ou pas ? */
|
||||
PyDoc_STRVAR(doc_addClause,
|
||||
"addClause(type='and'|'or'|'excl'|'phrase'|'near'|'sub', qstring=string,\n"
|
||||
PyDoc_STRVAR(doc_addclause,
|
||||
"addclause(type='and'|'or'|'excl'|'phrase'|'near'|'sub', qstring=string,\n"
|
||||
" slack=int, field=string, subSearch=SearchData)\n"
|
||||
"Adds a simple clause to the SearchData And/Or chain, or a subquery\n"
|
||||
"defined by another SearchData object\n"
|
||||
@ -95,14 +95,14 @@ PyDoc_STRVAR(doc_addClause,
|
||||
|
||||
/* Forward declaration only, definition needs recoll_searchDataType */
|
||||
static PyObject *
|
||||
SearchData_addClause(recoll_SearchDataObject* self, PyObject *args,
|
||||
SearchData_addclause(recoll_SearchDataObject* self, PyObject *args,
|
||||
PyObject *kwargs);
|
||||
|
||||
|
||||
|
||||
static PyMethodDef SearchData_methods[] = {
|
||||
{"addClause", (PyCFunction)SearchData_addClause, METH_VARARGS|METH_KEYWORDS,
|
||||
doc_addClause},
|
||||
{"addclause", (PyCFunction)SearchData_addclause, METH_VARARGS|METH_KEYWORDS,
|
||||
doc_addclause},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
@ -155,12 +155,12 @@ static PyTypeObject recoll_SearchDataType = {
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
SearchData_addClause(recoll_SearchDataObject* self, PyObject *args,
|
||||
SearchData_addclause(recoll_SearchDataObject* self, PyObject *args,
|
||||
PyObject *kwargs)
|
||||
{
|
||||
LOGDEB(("SearchData_addClause\n"));
|
||||
LOGDEB(("SearchData_addclause\n"));
|
||||
if (self->sd.isNull()) {
|
||||
LOGERR(("SearchData_addClause: not init??\n"));
|
||||
LOGERR(("SearchData_addclause: not init??\n"));
|
||||
PyErr_SetString(PyExc_AttributeError, "sd");
|
||||
return 0;
|
||||
}
|
||||
@ -617,8 +617,8 @@ Query_execute(recoll_QueryObject* self, PyObject *args, PyObject *kwargs)
|
||||
PyErr_SetString(PyExc_ValueError, reason.c_str());
|
||||
return 0;
|
||||
}
|
||||
sd->setSortBy(self->sortfield, self->ascending);
|
||||
RefCntr<Rcl::SearchData> rq(sd);
|
||||
rq->setSortBy(self->sortfield, self->ascending);
|
||||
self->query->setQuery(rq, dostem?Rcl::Query::QO_STEM:Rcl::Query::QO_NONE);
|
||||
int cnt = self->query->getResCnt();
|
||||
self->next = 0;
|
||||
@ -1045,7 +1045,8 @@ PyDoc_STRVAR(doc_DbObject,
|
||||
"Db([confdir=None], [extra_dbs=None], [writable = False])\n"
|
||||
"\n"
|
||||
"A Db object connects to a Recoll database.\n"
|
||||
"confdir specifies a Recoll configuration directory (default: environment).\n"
|
||||
"confdir specifies a Recoll configuration directory (default: \n"
|
||||
" $RECOLL_CONFDIR or ~/.recoll).\n"
|
||||
"extra_dbs is a list of external databases (xapian directories)\n"
|
||||
"writable decides if we can index new data through this connection\n"
|
||||
);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.16 2008-09-24 06:44:15 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.17 2008-09-29 06:58:25 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -222,12 +222,11 @@ int recollq(RclConfig **cfp, int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (op_flags & OPT_S) {
|
||||
sd->setSortBy(sortfield, (op_flags & OPT_D) ? false : true);
|
||||
}
|
||||
|
||||
RefCntr<Rcl::SearchData> rq(sd);
|
||||
Rcl::Query query(&rcldb);
|
||||
if (op_flags & OPT_S) {
|
||||
query.setSortBy(sortfield, (op_flags & OPT_D) ? false : true);
|
||||
}
|
||||
query.setQuery(rq, Rcl::Query::QO_STEM);
|
||||
int cnt = query.getResCnt();
|
||||
if (!(op_flags & OPT_b)) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.6 2008-09-16 08:18:30 dockes Exp $ (C) 2008 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.7 2008-09-29 06:58:25 dockes Exp $ (C) 2008 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -18,6 +18,7 @@ static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.6 2008-09-16 08:18:30 dockes Exp
|
||||
#include "conftree.h"
|
||||
#include "smallut.h"
|
||||
#include "searchdata.h"
|
||||
#include "rclconfig.h"
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
namespace Rcl {
|
||||
@ -88,7 +89,7 @@ private:
|
||||
};
|
||||
|
||||
Query::Query(Db *db)
|
||||
: m_nq(new Native(this)), m_db(db), m_sorter(0)
|
||||
: m_nq(new Native(this)), m_db(db), m_sorter(0), m_sortAscending(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -111,6 +112,13 @@ Db *Query::whatDb()
|
||||
return m_db;
|
||||
}
|
||||
|
||||
void Query::setSortBy(const string& fld, bool ascending) {
|
||||
RclConfig *cfg = RclConfig::getMainConfig();
|
||||
m_sortField = cfg->fieldCanon(stringtolower(fld));
|
||||
m_sortAscending = ascending;
|
||||
LOGDEB0(("RclQuery::setSortBy: [%s] %s\n", m_sortField.c_str(),
|
||||
m_sortAscending ? "ascending" : "descending"));
|
||||
}
|
||||
|
||||
//#define ISNULL(X) (X).isNull()
|
||||
#define ISNULL(X) !(X)
|
||||
@ -141,7 +149,8 @@ bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
||||
}
|
||||
|
||||
Xapian::Query xq;
|
||||
if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ? stemlang : string())) {
|
||||
if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ?
|
||||
stemlang : string())) {
|
||||
m_reason += sdata->getReason();
|
||||
return false;
|
||||
}
|
||||
@ -151,16 +160,16 @@ bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
||||
try {
|
||||
m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db);
|
||||
m_nq->enquire->set_query(m_nq->query);
|
||||
if (!sdata->getSortBy().empty()) {
|
||||
if (!m_sortField.empty()) {
|
||||
if (m_sorter) {
|
||||
delete (QSorter*)m_sorter;
|
||||
m_sorter = 0;
|
||||
}
|
||||
m_sorter = new QSorter(sdata->getSortBy());
|
||||
m_sorter = new QSorter(m_sortField);
|
||||
// It really seems there is a xapian bug about sort order, we
|
||||
// invert here.
|
||||
m_nq->enquire->set_sort_by_key((QSorter*)m_sorter,
|
||||
!sdata->getSortAscending());
|
||||
!m_sortAscending);
|
||||
}
|
||||
m_nq->mset = Xapian::MSet();
|
||||
// Get the query description and trim the "Xapian::Query"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _rclquery_h_included_
|
||||
#define _rclquery_h_included_
|
||||
/* @(#$Id: rclquery.h,v 1.3 2008-09-16 08:18:30 dockes Exp $ (C) 2008 J.F.Dockes */
|
||||
/* @(#$Id: rclquery.h,v 1.4 2008-09-29 06:58:25 dockes Exp $ (C) 2008 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
|
||||
@ -54,9 +54,14 @@ class Query {
|
||||
/** Get explanation about last error */
|
||||
string getReason() const;
|
||||
|
||||
/** Choose sort order. Must be called before setQuery */
|
||||
void setSortBy(const string& fld, bool ascending = true);
|
||||
const string& getSortBy() const {return m_sortField;}
|
||||
bool getSortAscending() const {return m_sortAscending;}
|
||||
|
||||
/** Accept data describing the search and query the index. This can
|
||||
* be called repeatedly on the same object which gets reinitialized each
|
||||
* time
|
||||
* time.
|
||||
*/
|
||||
bool setQuery(RefCntr<SearchData> q, int opts = QO_NONE,
|
||||
const string& stemlang = "english");
|
||||
@ -89,6 +94,8 @@ private:
|
||||
Db *m_db;
|
||||
void *m_sorter;
|
||||
unsigned int m_qOpts;
|
||||
string m_sortField;
|
||||
bool m_sortAscending;
|
||||
/* Copyconst and assignement private and forbidden */
|
||||
Query(const Query &) {}
|
||||
Query & operator=(const Query &) {return *this;};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.23 2008-09-16 08:18:30 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.24 2008-09-29 06:58:25 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -153,14 +153,6 @@ void SearchData::erase() {
|
||||
m_reason.erase();
|
||||
}
|
||||
|
||||
void SearchData::setSortBy(const string& fld, bool ascending) {
|
||||
RclConfig *cfg = RclConfig::getMainConfig();
|
||||
m_sortField = cfg->fieldCanon(stringtolower(fld));
|
||||
m_sortAscending = ascending;
|
||||
LOGDEB0(("SearchData::setSortBy: [%s] %s\n", m_sortField.c_str(),
|
||||
m_sortAscending ? "ascending" : "descending"));
|
||||
}
|
||||
|
||||
// Am I a file name only search ? This is to turn off term highlighting
|
||||
bool SearchData::fileNameOnly()
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _SEARCHDATA_H_INCLUDED_
|
||||
#define _SEARCHDATA_H_INCLUDED_
|
||||
/* @(#$Id: searchdata.h,v 1.18 2008-09-16 08:18:30 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: searchdata.h,v 1.19 2008-09-29 06:58:25 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
/**
|
||||
* Structures to hold data coming almost directly from the gui
|
||||
@ -110,17 +110,11 @@ public:
|
||||
/** Add file type for filtering results */
|
||||
void addFiletype(const string& ft) {m_filetypes.push_back(ft);}
|
||||
|
||||
/** Choose sort order. Should this be in RclQuery instead ? */
|
||||
void setSortBy(const string& fld, bool ascending = true);
|
||||
const string& getSortBy() const {return m_sortField;}
|
||||
bool getSortAscending() const {return m_sortAscending;}
|
||||
private:
|
||||
SClType m_tp; // Only SCLT_AND or SCLT_OR here
|
||||
vector<SearchDataClause*> m_query;
|
||||
vector<string> m_filetypes; // Restrict to filetypes if set.
|
||||
string m_topdir; // Restrict to subtree.
|
||||
string m_sortField;
|
||||
bool m_sortAscending;
|
||||
// Printable expanded version of the complete query, retrieved/set
|
||||
// from rcldb after the Xapian::setQuery() call
|
||||
string m_description;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user