1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
/* This file is part of Strigi Desktop Search
*
* Copyright (C) 2007 Jos van den Oever <jos@vandenoever.info>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <strigi/query.h>
using namespace std;
using namespace Strigi;
class Strigi::TermPrivate {
public:
int64_t i_value; // value for Integer, Date and Boolean
double d_value; // value for Float
std::string s_value; // value for String
// flags for String terms (ordered by size)
std::string language;
float fuzzy;
int slack;
int proximityDistance;
Term::Type type;
bool phrase;
bool caseSensitive;
bool diacriticSensitive;
bool ordered;
bool enableStemming;
bool wordbased;
TermPrivate()
: i_value(0), d_value(0.0), fuzzy(0.0), slack(0), proximityDistance(10)
, type(Term::String), phrase(true), caseSensitive(true)
, diacriticSensitive(true), ordered(true), enableStemming(false)
, wordbased(true)
{}
};
class Strigi::QueryPrivate {
public:
// Selection fields
Term term;
Term termTwo; // needed for Proximity
std::vector<std::string> fields;
// Collectible fields
std::vector<Query> subs;
// Shared fields
float boost;
bool negate;
// Type
Query::Type type;
bool valid;
QueryPrivate() :boost(1), negate(false), type(Query::Contains), valid(true)
{}
};
Term::Term() :p(new TermPrivate()) {
}
Term::Term(const Term& t) :p(new TermPrivate(*t.p)) {
}
Term::~Term() {
delete p;
}
void
Term::operator=(const Term& t) {
*p = *t.p;
}
int
Term::proximityDistance() const {
return p->proximityDistance;
}
void
Term::setProximityDistance(int d) {
p->proximityDistance = d;
}
bool
Term::caseSensitive() const {
return p->caseSensitive;
}
void
Term::setCaseSensitive(bool b) {
p->caseSensitive = b;
}
bool
Term::diacriticSensitive() const {
return p->diacriticSensitive;
}
void
Term::setDiacriticSensitive(bool b) {
p->diacriticSensitive = b;
}
bool
Term::stemming() const {
return p->enableStemming;
}
void
Term::setStemming(bool b) {
p->enableStemming = b;
}
float
Term::fuzzy() const {
return p->fuzzy;
}
void
Term::setFuzzy(float f) {
p->fuzzy = f;
}
int
Term::slack() const {
return p->slack;
}
void
Term::setSlack(int s) {
p->slack = s;
}
bool
Term::ordered() const {
return p->ordered;
}
void
Term::setOrdered(bool b) {
p->ordered = b;
}
bool
Term::wordBased() const {
return p->wordbased;
}
void
Term::setWordBased(bool b) {
p->wordbased = b;
}
void
Term::setValue(const std::string& s) {
p->s_value = s;
p->type = String;
}
void
Term::setValue(const char* s) {
p->s_value.assign(s);
p->type = String;
}
const string&
Term::string() const {
return p->s_value;
}
ostream&
operator<< ( ostream &stream, Strigi::Term term ) {
stream << "<term>" << endl;
stream << "<slack>" << term.slack() << "</slack>" << endl;
stream << "<fuzzy>" << term.fuzzy() << "</fuzzy>" << endl;
stream << "<string>" << term.string() << "</string>" << endl;
stream << "<proximityDistance>" << term.proximityDistance()
<< "</proximityDistance>" << endl;
stream << "<stemming>" << ( term.stemming() ? "yes" : "no" )
<< "</stemming>" << endl;
stream << "<ordered>" << ( term.ordered() ? "yes" : "no" )
<< "</ordered>" << endl;
stream << "<diacriticSensitive>"
<< ( term.diacriticSensitive() ? "yes" : "no" )
<< "</diacriticSensitive>" << endl;
stream << "<wordbased>" << ( term.wordBased() ? "yes" : "no" )
<< "</wordbased>" << endl;
stream << "<caseSensitive>" << ( term.caseSensitive() ? "yes" : "no" )
<< "</caseSensitive>" << endl;
stream << "</term>" << endl;
return stream;
}
Query::Query() :p(new QueryPrivate()) {
}
Query::Query(const Query& t) :p(new QueryPrivate(*t.p)) {
}
Query::~Query() {
delete p;
}
void
Query::operator=(const Query& q) {
*p = *q.p;
}
Term&
Query::term() {
return p->term;
}
const Term&
Query::term() const {
return p->term;
}
void
Query::setTerm(const Term& t) {
p->term = t;
}
float
Query::boost() const {
return p->boost;
}
void
Query::setBoost(float b) {
p->boost = b;
}
Query::Type
Query::type() const {
return p->type;
}
void
Query::setType(Type t) {
p->type = t;
}
bool
Query::negate() const {
return p->negate;
}
void
Query::setNegate(bool n) {
p->negate = n;
}
const vector<string>&
Query::fields() const {
return p->fields;
}
vector<string>&
Query::fields() {
return p->fields;
}
const vector<Query>&
Query::subQueries() const {
return p->subs;
}
vector<Query>&
Query::subQueries() {
return p->subs;
}
bool
Query::valid() const {
return p->valid;
}
ostream &
operator<< ( ostream &stream, Strigi::Query query )
{
stream << "<query>" << endl;
stream << query.term();
stream << "<Boost>" << query.boost() << "</Boost>" << endl;
stream << "<negate>" << ( query.negate() ? "yes" : "no" )
<< "</negate>" << endl;
for ( std::vector<string>::iterator it = query.fields().begin();
it != query.fields().end(); ++it )
{
stream << "<field>"<< *it << "</field>" << endl;
}
if ( query.fields().size() == 0 )
stream << "<field/>" << endl;
string typeTag;
switch ( query.type() )
{
case Strigi::Query::And:
stream << "<And>" << endl;
typeTag = "And";
break;
case Strigi::Query::Or:
stream << "<Or>" << endl;
typeTag = "Or";
break;
case Strigi::Query::Proximity:
stream << "<Proximity>" << endl;
typeTag = "Proximity";
break;
case Strigi::Query::RegExp:
stream << "<RegExp>" << endl;
typeTag = "RegExp";
break;
case Strigi::Query::Equals:
stream << "<Equals>" << endl;
typeTag = "Equals";
break;
case Strigi::Query::Contains:
stream << "<Contains>" << endl;
typeTag = "Contains";
break;
case Strigi::Query::LessThan:
stream << "<LessThan>" << endl;
typeTag = "LessThan";
break;
case Strigi::Query::LessThanEquals:
stream << "<LessThanEquals>" << endl;
typeTag = "LessThanEquals";
break;
case Strigi::Query::GreaterThan:
stream << "<GreaterThan>" << endl;
typeTag = "GreaterThan";
break;
case Strigi::Query::GreaterThanEquals:
stream << "<GreaterThanEquals>" << endl;
typeTag = "GreaterThanEquals";
break;
case Strigi::Query::StartsWith:
stream << "<StartsWith>" << endl;
typeTag = "StartsWith";
break;
case Strigi::Query::FullText:
stream << "<FullText>" << endl;
typeTag = "FullText";
break;
case Strigi::Query::Keyword:
stream << "<Keyword>" << endl;
typeTag = "Keyword";
break;
}
if (!query.subQueries().empty())
{
stream << "<subQueries>" << endl;
unsigned int counter = 0;
for ( std::vector<Strigi::Query>::iterator it = query.subQueries().begin();
it != query.subQueries().end(); it++, counter++ )
{
Strigi::Query subQuery = *it;
stream << subQuery;
}
stream << "</subQueries>" << endl;
}
stream << "</" << typeTag << ">" << endl;
stream << "</query>" << endl;
return stream;
}
|