Switch to unified view

a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.6 2008-09-16 08:18:30 dockes Exp $ (C) 2008 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.7 2008-09-29 06:58:25 dockes Exp $ (C) 2008 J.F.Dockes";
3
#endif
3
#endif
4
4
5
#include <stdlib.h>
5
#include <stdlib.h>
6
#include <string.h>
6
#include <string.h>
7
7
...
...
16
#include "rclquery_p.h"
16
#include "rclquery_p.h"
17
#include "debuglog.h"
17
#include "debuglog.h"
18
#include "conftree.h"
18
#include "conftree.h"
19
#include "smallut.h"
19
#include "smallut.h"
20
#include "searchdata.h"
20
#include "searchdata.h"
21
#include "rclconfig.h"
21
22
22
#ifndef NO_NAMESPACES
23
#ifndef NO_NAMESPACES
23
namespace Rcl {
24
namespace Rcl {
24
#endif
25
#endif
25
26
...
...
86
private:
87
private:
87
    string m_fld;
88
    string m_fld;
88
};
89
};
89
90
90
Query::Query(Db *db)
91
Query::Query(Db *db)
91
    : m_nq(new Native(this)), m_db(db), m_sorter(0)
92
    : m_nq(new Native(this)), m_db(db), m_sorter(0), m_sortAscending(true)
92
{
93
{
93
}
94
}
94
95
95
Query::~Query()
96
Query::~Query()
96
{
97
{
...
...
109
Db *Query::whatDb() 
110
Db *Query::whatDb() 
110
{
111
{
111
    return m_db;
112
    return m_db;
112
}
113
}
113
114
115
void Query::setSortBy(const string& fld, bool ascending) {
116
    RclConfig *cfg = RclConfig::getMainConfig();
117
    m_sortField = cfg->fieldCanon(stringtolower(fld));
118
    m_sortAscending = ascending;
119
    LOGDEB0(("RclQuery::setSortBy: [%s] %s\n", m_sortField.c_str(),
120
       m_sortAscending ? "ascending" : "descending"));
121
}
114
122
115
//#define ISNULL(X) (X).isNull()
123
//#define ISNULL(X) (X).isNull()
116
#define ISNULL(X) !(X)
124
#define ISNULL(X) !(X)
117
125
118
// Prepare query out of user search data
126
// Prepare query out of user search data
...
...
139
#endif
147
#endif
140
        new FilterMatcher(m_filterTopDir);
148
        new FilterMatcher(m_filterTopDir);
141
    }
149
    }
142
150
143
    Xapian::Query xq;
151
    Xapian::Query xq;
144
    if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ? stemlang : string())) {
152
    if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ? 
153
                stemlang : string())) {
145
    m_reason += sdata->getReason();
154
    m_reason += sdata->getReason();
146
    return false;
155
    return false;
147
    }
156
    }
148
    m_nq->query = xq;
157
    m_nq->query = xq;
149
    string ermsg;
158
    string ermsg;
150
    string d;
159
    string d;
151
    try {
160
    try {
152
    m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db);
161
    m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db);
153
    m_nq->enquire->set_query(m_nq->query);
162
    m_nq->enquire->set_query(m_nq->query);
154
  if (!sdata->getSortBy().empty()) {
163
  if (!m_sortField.empty()) {
155
        if (m_sorter) {
164
        if (m_sorter) {
156
        delete (QSorter*)m_sorter;
165
        delete (QSorter*)m_sorter;
157
        m_sorter = 0;
166
        m_sorter = 0;
158
        }
167
        }
159
        m_sorter = new QSorter(sdata->getSortBy());
168
        m_sorter = new QSorter(m_sortField);
160
        // It really seems there is a xapian bug about sort order, we 
169
        // It really seems there is a xapian bug about sort order, we 
161
        // invert here.
170
        // invert here.
162
        m_nq->enquire->set_sort_by_key((QSorter*)m_sorter, 
171
        m_nq->enquire->set_sort_by_key((QSorter*)m_sorter, 
163
                       !sdata->getSortAscending());
172
                       !m_sortAscending);
164
    }
173
    }
165
    m_nq->mset = Xapian::MSet();
174
    m_nq->mset = Xapian::MSet();
166
    // Get the query description and trim the "Xapian::Query"
175
    // Get the query description and trim the "Xapian::Query"
167
    d = m_nq->query.get_description();
176
    d = m_nq->query.get_description();
168
    } XCATCHERROR(ermsg);
177
    } XCATCHERROR(ermsg);