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                                           "SELECT ?r WHERE { ?r a nco:Contact }" 
   69 static QString containsQueryString( 
bool doWholeWordSearch, 
bool matchWordBoundary )
 
   71   if ( doWholeWordSearch ) {
 
   72     return QString::fromLatin1( 
"?v bif:contains \"'%1'\" . " );
 
   74       if ( matchWordBoundary ) {
 
   75           return QString::fromLatin1( 
"?v bif:contains \"'%1*'\" . " );
 
   77           return QString::fromLatin1( 
"FILTER regex(str(?v), \"%1\", \"i\")" );
 
   88   const bool doWholeWordSearch = value.size() < 3;
 
   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 nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. " 
  121     } 
else if ( criterion == 
Email ) {
 
  122       query += QString::fromLatin1(
 
  123 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  128           "        <field name=\"type\"/>" 
  129           "        <string>PersonContact</string>" 
  132           "        <field name=\"emailAddress\"/>" 
  133           "        <string>%1</string>" 
  139           "SELECT DISTINCT ?person ?reqProp1 " 
  143           "    ?person nco:hasEmailAddress ?email . " 
  144           "    ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . " 
  149     } 
else if ( criterion == 
NickName ) {
 
  150       query += QString::fromLatin1(
 
  151 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  156           "        <field name=\"type\"/>" 
  157           "        <string>PersonContact</string>" 
  160           "        <field name=\"nickname\"/>" 
  161           "        <string>%1</string>" 
  167           "SELECT DISTINCT ?r ?reqProp1 " 
  171           "    ?r nco:nickname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ." 
  177       query += QString::fromLatin1(
 
  178 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  183           "        <field name=\"type\"/>" 
  184           "        <string>PersonContact</string>" 
  188           "          <field name=\"fullname\"/>" 
  189           "          <string>%1</string>" 
  192           "          <field name=\"nameGiven\"/>" 
  193           "          <string>%1</string>" 
  196           "          <field name=\"nameFamily\"/>" 
  197           "          <string>%1</string>" 
  200           "          <field name=\"emailAddress\"/>" 
  201           "          <string>%1</string>" 
  208           "SELECT DISTINCT ?r ?reqProp1 " 
  212           "    { ?r ?p \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. " 
  213           "      FILTER(?p in (nco:fullname, nco:nameGiven, nco:nameFamily, nco:nameAdditional)) . }" 
  215           "    { ?r nco:hasEmailAddress ?email . " 
  216           "      ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . } " 
  222       query += QString::fromLatin1(
 
  223 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  228           "        <field name=\"type\"/>" 
  229           "        <string>PersonContact</string>" 
  232           "        <field name=\"contactUID\"/>" 
  233           "        <string>%1</string>" 
  239           "SELECT DISTINCT ?r ?reqProp1 " 
  243           "    ?r nco:contactUID \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ." 
  250     if ( criterion == 
Name ) {
 
  251       query += QString::fromLatin1(
 
  252 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  257           "        <field name=\"type\"/>" 
  258           "        <string>PersonContact</string>" 
  261           "        <field name=\"fullname\"/>" 
  262           "        <string>%1</string>" 
  268           "SELECT DISTINCT ?r ?reqProp1 " 
  272           "    ?r nco:fullname ?v . " 
  273           "    ?v bif:contains \"'%1*'\" . " 
  278     } 
else if ( criterion == 
Email ) {
 
  279       query += QString::fromLatin1(
 
  280 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  285           "        <field name=\"type\"/>" 
  286           "        <string>PersonContact</string>" 
  289           "        <field name=\"emailAddress\"/>" 
  290           "        <string>%1</string>" 
  296           "SELECT DISTINCT ?person ?reqProp1 " 
  300           "    ?person nco:hasEmailAddress ?email . " 
  301           "    ?email nco:emailAddress ?v . " 
  302           "    ?v bif:contains \"'%1\'\" . " 
  307     } 
else if ( criterion == 
NickName ) {
 
  308       query += QString::fromLatin1(
 
  309 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  314           "        <field name=\"type\"/>" 
  315           "        <string>PersonContact</string>" 
  318           "        <field name=\"nickname\"/>" 
  319           "        <string>%1</string>" 
  325           "SELECT DISTINCT ?r ?reqProp1 " 
  329           "    ?r nco:nickname ?v . " 
  330           "    ?v bif:contains \"'%1\'\" . " 
  336       query += QString::fromLatin1(
 
  337 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  342           "        <field name=\"type\"/>" 
  343           "        <string>PersonContact</string>" 
  347           "          <field name=\"fullname\"/>" 
  348           "          <string>%1</string>" 
  351           "          <field name=\"nameGiven\"/>" 
  352           "          <string>%1</string>" 
  355           "          <field name=\"nameFamily\"/>" 
  356           "          <string>%1</string>" 
  359           "          <field name=\"emailAddress\"/>" 
  360           "          <string>%1</string>" 
  367           "SELECT DISTINCT ?r ?reqProp1 " 
  372           "      FILTER(?p in (nco:fullname, nco:nameGiven, nco:nameFamily, nco:nameAdditional)). " 
  373           "      ?v bif:contains \"'%1'\" . }" 
  375           "    { ?r nco:hasEmailAddress ?email . " 
  376           "      ?email nco:emailAddress ?v . " 
  377           "      ?v bif:contains \"'%1'\" . }" 
  383       query += QString::fromLatin1(
 
  384 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  389           "        <field name=\"type\"/>" 
  390           "        <string>PersonContact</string>" 
  393           "        <field name=\"contactUID\"/>" 
  394           "        <string>%1</string>" 
  400           "SELECT DISTINCT ?r ?reqProp1 " 
  404           "    ?r nco:contactUID ?v . " 
  405           "    ?v bif:contains \"'%1*'\" . " 
  412     if ( criterion == 
Name ) {
 
  413       query += QString::fromLatin1(
 
  414 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  419           "        <field name=\"type\"/>" 
  420           "        <string>PersonContact</string>" 
  423           "        <field name=\"fullname\"/>" 
  424           "        <string>%1</string>" 
  430           "SELECT DISTINCT ?r ?reqProp1 " 
  434           "    ?r nco:fullname ?v . " 
  440       query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
 
  441     } 
else if ( criterion == 
Email ) {
 
  442       query += QString::fromLatin1(
 
  443 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  448           "        <field name=\"type\"/>" 
  449           "        <string>PersonContact</string>" 
  452           "        <field name=\"emailAddress\"/>" 
  453           "        <string>%1</string>" 
  459           "SELECT DISTINCT ?person ?reqProp1 " 
  463           "    ?person nco:hasEmailAddress ?email . " 
  464           "    ?email nco:emailAddress ?v . " 
  470       query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
 
  471     } 
else if ( criterion == 
NickName ) {
 
  472       query += QString::fromLatin1(
 
  473 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  478           "        <field name=\"type\"/>" 
  479           "        <string>PersonContact</string>" 
  482           "        <field name=\"nickname\"/>" 
  483           "        <string>%1</string>" 
  489           "SELECT DISTINCT ?r ?reqProp1 " 
  493           "    ?r nco:nickname ?v . " 
  499       query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
 
  501       query += QString::fromLatin1(
 
  502 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  507           "        <field name=\"type\"/>" 
  508           "        <string>PersonContact</string>" 
  512           "          <field name=\"fullname\"/>" 
  513           "          <string>%1</string>" 
  516           "          <field name=\"nameGiven\"/>" 
  517           "          <string>%1</string>" 
  520           "          <field name=\"nameFamily\"/>" 
  521           "          <string>%1</string>" 
  524           "          <field name=\"emailAddress\"/>" 
  525           "          <string>%1</string>" 
  532           "SELECT DISTINCT ?r ?reqProp1 " 
  537           "      FILTER(?p in (nco:fullname, nco:nameGiven, nco:nameFamily, nco:nameAdditional) ) ." 
  539           "    { ?r nco:hasEmailAddress ?email . " 
  540           "      ?email nco:emailAddress ?v . " 
  546       query = query.arg( containsQueryString( doWholeWordSearch, matchWordBoundary ) );
 
  548       query += QString::fromLatin1(
 
  549 #ifdef AKONADI_USE_STRIGI_SEARCH
 
  554           "        <field name=\"type\"/>" 
  555           "        <string>Contact</string>" 
  558           "        <field name=\"contactUID\"/>" 
  559           "        <string>%1</string>" 
  565           "SELECT DISTINCT ?r ?reqProp1 " 
  569           "    ?r nco:contactUID ?v . " 
  570           "    ?v bif:contains \"'%1'\" . " 
  578   if ( d->mLimit != -1 ) {
 
  579 #ifndef AKONADI_USE_STRIGI_SEARCH 
  580     query += QString::fromLatin1( 
" LIMIT %1" ).arg( d->mLimit );
 
  583   query = query.arg( value );
 
  597   foreach ( 
const Item &item, 
items() ) {
 
  598     if ( item.hasPayload<KABC::Addressee>() ) {
 
  599       contacts.append( item.payload<KABC::Addressee>() );
 
Item::List items() const 
Returns the items that matched the search query. 
 
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched. 
 
ItemFetchScope & fetchScope()
Returns the item fetch scope. 
 
static QUrl akonadiItemIdUri()
Returns an URI that represents a predicate that is always added to the Nepomuk resource by the Akonad...
 
void setQuery(const QString &query)
Sets the search query in SPARQL format. 
 
Job that searches for items in the Akonadi storage.