move sort params from searchdata to rclquery
This commit is contained in:
+15
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user