|
a/src/rcldb/searchdata.cpp |
|
b/src/rcldb/searchdata.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.21 2008-01-16 11:14:38 dockes Exp $ (C) 2006 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.22 2008-08-28 15:42:43 dockes Exp $ (C) 2006 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
46 |
bool SearchData::toNativeQuery(Rcl::Db &db, void *d, const string& stemlang)
|
46 |
bool SearchData::toNativeQuery(Rcl::Db &db, void *d, const string& stemlang)
|
47 |
{
|
47 |
{
|
48 |
Xapian::Query xq;
|
48 |
Xapian::Query xq;
|
49 |
m_reason.erase();
|
49 |
m_reason.erase();
|
50 |
|
50 |
|
|
|
51 |
if (m_query.size() < 1) {
|
|
|
52 |
m_reason = "empty query";
|
|
|
53 |
return false;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// It's not allowed to have a pure negative query and also it
|
|
|
57 |
// seems that Xapian doesn't like the first element to be AND_NOT
|
|
|
58 |
qlist_it_t itnotneg = m_query.end();
|
|
|
59 |
for (qlist_it_t it = m_query.begin(); it != m_query.end(); it++) {
|
|
|
60 |
if ((*it)->m_tp != SCLT_EXCL) {
|
|
|
61 |
itnotneg = it;
|
|
|
62 |
break;
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
if (itnotneg == m_query.end()) {
|
|
|
66 |
LOGERR(("SearchData::toNativeQuery: can't have all negative clauses"));
|
|
|
67 |
m_reason = "Can't have only negative clauses";
|
|
|
68 |
return false;
|
|
|
69 |
}
|
|
|
70 |
if ((*m_query.begin())->m_tp == SCLT_EXCL)
|
|
|
71 |
iter_swap(m_query.begin(), itnotneg);
|
|
|
72 |
|
51 |
// Walk the clause list translating each in turn and building the
|
73 |
// Walk the clause list translating each in turn and building the
|
52 |
// Xapian query tree
|
74 |
// Xapian query tree
|
53 |
for (qlist_it_t it = m_query.begin(); it != m_query.end(); it++) {
|
75 |
for (qlist_it_t it = m_query.begin(); it != m_query.end(); it++) {
|
54 |
Xapian::Query nq;
|
76 |
Xapian::Query nq;
|
55 |
if (!(*it)->toNativeQuery(db, &nq, stemlang)) {
|
77 |
if (!(*it)->toNativeQuery(db, &nq, stemlang)) {
|
|
... |
|
... |
57 |
m_reason = (*it)->getReason();
|
79 |
m_reason = (*it)->getReason();
|
58 |
return false;
|
80 |
return false;
|
59 |
}
|
81 |
}
|
60 |
|
82 |
|
61 |
// If this structure is an AND list, must use AND_NOT for excl clauses.
|
83 |
// If this structure is an AND list, must use AND_NOT for excl clauses.
|
62 |
// Else this is an OR list, and there can't be excl clauses
|
84 |
// Else this is an OR list, and there can't be excl clauses (checked by
|
|
|
85 |
// addClause())
|
63 |
Xapian::Query::op op;
|
86 |
Xapian::Query::op op;
|
64 |
if (m_tp == SCLT_AND) {
|
87 |
if (m_tp == SCLT_AND) {
|
65 |
op = (*it)->m_tp == SCLT_EXCL ?
|
88 |
op = (*it)->m_tp == SCLT_EXCL ?
|
66 |
Xapian::Query::OP_AND_NOT: Xapian::Query::OP_AND;
|
89 |
Xapian::Query::OP_AND_NOT: Xapian::Query::OP_AND;
|
67 |
} else {
|
90 |
} else {
|