22 #include "contactsearchjob.h"
24 #include <akonadi/itemfetchscope.h>
26 using namespace Akonadi;
28 class ContactSearchJob::Private
42 #ifdef AKONADI_USE_STRIGI_SEARCH
46 " <field name=\"type\"/>"
47 " <string>PersonContact</string>"
52 "prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
53 "SELECT ?r WHERE { ?r a nco:Contact }"
70 static QString containsQueryString(
bool doWholeWordSearch,
bool matchWordBoundary )
72 if ( doWholeWordSearch )
73 return QString::fromLatin1(
"?v bif:contains \"'%1'\" . " );
75 return QString::fromLatin1(
"FILTER regex(str(?v), \"%1\", \"i\")" )
76 .arg( matchWordBoundary? QLatin1String(
"\\\\b%1") : QLatin1String(
"%1") );
84 const bool doWholeWordSearch = value.size() < 3;
89 #ifndef AKONADI_USE_STRIGI_SEARCH
90 query = QString::fromLatin1(
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>" );
94 if ( criterion ==
Name ) {
95 query += QString::fromLatin1(
96 #ifdef AKONADI_USE_STRIGI_SEARCH
101 " <field name=\"type\"/>"
102 " <string>PersonContact</string>"
105 " <field name=\"fullname\"/>"
106 " <string>%1</string>"
112 "SELECT DISTINCT ?r ?reqProp1 "
116 " ?r a nco:Contact . "
117 " ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. "
122 }
else if ( criterion ==
Email ) {
123 query += QString::fromLatin1(
124 #ifdef AKONADI_USE_STRIGI_SEARCH
129 " <field name=\"type\"/>"
130 " <string>PersonContact</string>"
133 " <field name=\"emailAddress\"/>"
134 " <string>%1</string>"
140 "SELECT DISTINCT ?person ?reqProp1 "
144 " ?person a nco:Contact ; "
145 " nco:hasEmailAddress ?email . "
146 " ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . "
151 }
else if ( criterion ==
NickName ) {
152 query += QString::fromLatin1(
153 #ifdef AKONADI_USE_STRIGI_SEARCH
158 " <field name=\"type\"/>"
159 " <string>PersonContact</string>"
162 " <field name=\"nickname\"/>"
163 " <string>%1</string>"
169 "SELECT DISTINCT ?r ?reqProp1 "
173 " ?r a nco:Contact . "
174 " ?r nco:nickname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ."
180 query += QString::fromLatin1(
181 #ifdef AKONADI_USE_STRIGI_SEARCH
186 " <field name=\"type\"/>"
187 " <string>PersonContact</string>"
191 " <field name=\"fullname\"/>"
192 " <string>%1</string>"
195 " <field name=\"nameGiven\"/>"
196 " <string>%1</string>"
199 " <field name=\"nameFamily\"/>"
200 " <string>%1</string>"
203 " <field name=\"emailAddress\"/>"
204 " <string>%1</string>"
211 "SELECT DISTINCT ?r ?reqProp1 "
215 " ?r a nco:Contact . "
216 " { ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. } "
218 " { ?r nco:nameGiven \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. } "
220 " { ?r nco:nameFamily \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. } "
222 " { ?r nco:hasEmailAddress ?email . "
223 " ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . } "
229 query += QString::fromLatin1(
230 #ifdef AKONADI_USE_STRIGI_SEARCH
235 " <field name=\"type\"/>"
236 " <string>PersonContact</string>"
239 " <field name=\"contactUID\"/>"
240 " <string>%1</string>"
246 "SELECT DISTINCT ?r ?reqProp1 "
250 " ?r a nco:Contact . "
251 " ?r nco:contactUID \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ."
258 if ( criterion ==
Name ) {
259 query += QString::fromLatin1(
260 #ifdef AKONADI_USE_STRIGI_SEARCH
265 " <field name=\"type\"/>"
266 " <string>PersonContact</string>"
269 " <field name=\"fullname\"/>"
270 " <string>%1</string>"
276 "SELECT DISTINCT ?r ?reqProp1 "
280 " ?r a nco:Contact . "
281 " ?r nco:fullname ?v . "
282 " ?v bif:contains \"'%1*'\" . "
287 }
else if ( criterion ==
Email ) {
288 query += QString::fromLatin1(
289 #ifdef AKONADI_USE_STRIGI_SEARCH
294 " <field name=\"type\"/>"
295 " <string>PersonContact</string>"
298 " <field name=\"emailAddress\"/>"
299 " <string>%1</string>"
305 "SELECT DISTINCT ?person ?reqProp1 "
309 " ?person a nco:Contact ; "
310 " nco:hasEmailAddress ?email . "
311 " ?email nco:emailAddress ?v . "
312 " FILTER regex(str(?v), \"^%1\", \"i\") "
317 }
else if ( criterion ==
NickName ) {
318 query += QString::fromLatin1(
319 #ifdef AKONADI_USE_STRIGI_SEARCH
324 " <field name=\"type\"/>"
325 " <string>PersonContact</string>"
328 " <field name=\"nickname\"/>"
329 " <string>%1</string>"
335 "SELECT DISTINCT ?r ?reqProp1 "
339 " ?r a nco:Contact . "
340 " ?r nco:nickname ?v . "
341 " FILTER regex(str(?v), \"^%1\", \"i\") "
347 query += QString::fromLatin1(
348 #ifdef AKONADI_USE_STRIGI_SEARCH
353 " <field name=\"type\"/>"
354 " <string>PersonContact</string>"
358 " <field name=\"fullname\"/>"
359 " <string>%1</string>"
362 " <field name=\"nameGiven\"/>"
363 " <string>%1</string>"
366 " <field name=\"nameFamily\"/>"
367 " <string>%1</string>"
370 " <field name=\"emailAddress\"/>"
371 " <string>%1</string>"
378 "SELECT DISTINCT ?r ?reqProp1 "
382 " ?r a nco:Contact . "
383 " { ?r nco:fullname ?v . "
384 " FILTER regex(str(?v), \"^%1\", \"i\") } "
386 " { ?r nco:nameGiven ?v . "
387 " FILTER regex(str(?v), \"^%1\", \"i\") } "
389 " { ?r nco:nameFamily ?v . "
390 " FILTER regex(str(?v), \"^%1\", \"i\") } "
392 " { ?r nco:hasEmailAddress ?email . "
393 " ?email nco:emailAddress ?v . "
394 " FILTER regex(str(?v), \"^%1\", \"i\") } "
400 query += QString::fromLatin1(
401 #ifdef AKONADI_USE_STRIGI_SEARCH
406 " <field name=\"type\"/>"
407 " <string>PersonContact</string>"
410 " <field name=\"contactUID\"/>"
411 " <string>%1</string>"
417 "SELECT DISTINCT ?r ?reqProp1 "
421 " ?r a nco:Contact . "
422 " ?r nco:contactUID ?v . "
423 " ?v bif:contains \"'%1*'\" . "
430 if ( criterion ==
Name ) {
431 query += QString::fromLatin1(
432 #ifdef AKONADI_USE_STRIGI_SEARCH
437 " <field name=\"type\"/>"
438 " <string>PersonContact</string>"
441 " <field name=\"fullname\"/>"
442 " <string>%1</string>"
448 "SELECT DISTINCT ?r ?reqProp1 "
452 " ?r a nco:Contact . "
453 " ?r nco:fullname ?v . "
459 query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
460 }
else if ( criterion ==
Email ) {
461 query += QString::fromLatin1(
462 #ifdef AKONADI_USE_STRIGI_SEARCH
467 " <field name=\"type\"/>"
468 " <string>PersonContact</string>"
471 " <field name=\"emailAddress\"/>"
472 " <string>%1</string>"
478 "SELECT DISTINCT ?person ?reqProp1 "
482 " ?person a nco:Contact ; "
483 " nco:hasEmailAddress ?email . "
484 " ?email nco:emailAddress ?v . "
490 query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
491 }
else if ( criterion ==
NickName ) {
492 query += QString::fromLatin1(
493 #ifdef AKONADI_USE_STRIGI_SEARCH
498 " <field name=\"type\"/>"
499 " <string>PersonContact</string>"
502 " <field name=\"nickname\"/>"
503 " <string>%1</string>"
509 "SELECT DISTINCT ?r ?reqProp1 "
513 " ?r a nco:Contact . "
514 " ?r nco:nickname ?v . "
520 query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
522 query += QString::fromLatin1(
523 #ifdef AKONADI_USE_STRIGI_SEARCH
528 " <field name=\"type\"/>"
529 " <string>PersonContact</string>"
533 " <field name=\"fullname\"/>"
534 " <string>%1</string>"
537 " <field name=\"nameGiven\"/>"
538 " <string>%1</string>"
541 " <field name=\"nameFamily\"/>"
542 " <string>%1</string>"
545 " <field name=\"emailAddress\"/>"
546 " <string>%1</string>"
553 "SELECT DISTINCT ?r ?reqProp1 "
557 " ?r a nco:Contact . "
558 " { ?r nco:fullname ?v . "
561 " { ?r nco:nameGiven ?v . "
564 " { ?r nco:nameFamily ?v . "
567 " { ?r nco:hasEmailAddress ?email . "
568 " ?email nco:emailAddress ?v . "
574 query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
576 query += QString::fromLatin1(
577 #ifdef AKONADI_USE_STRIGI_SEARCH
582 " <field name=\"type\"/>"
583 " <string>Contact</string>"
586 " <field name=\"contactUID\"/>"
587 " <string>%1</string>"
593 "SELECT DISTINCT ?r ?reqProp1 "
597 " ?r a nco:Contact . "
598 " ?r nco:contactUID ?v . "
599 " ?v bif:contains \"'%1'\" . "
607 if ( d->mLimit != -1 ) {
608 #ifndef AKONADI_USE_STRIGI_SEARCH
609 query += QString::fromLatin1(
" LIMIT %1" ).arg( d->mLimit );
612 query = query.arg( value );
628 contacts.append( item.
payload<KABC::Addressee>() );
634 #include "contactsearchjob.moc"