Commit eb6f5cf8 authored by Tobias Koenig's avatar Tobias Koenig

Extend ContactSearchJob by matching modes and NameOrEmail criterion

svn path=/trunk/KDE/kdepimlibs/; revision=1105640
parent c7ef3e90
......@@ -50,41 +50,165 @@ ContactSearchJob::~ContactSearchJob()
void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
{
setQuery( criterion, value, ContainsMatch );
}
void ContactSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
{
if ( match == StartsWithMatch && value.size() < 4 )
match = ExactMatch;
QString query = QString::fromLatin1(
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>" );
if ( criterion == Name ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. "
" } "
"} " );
} else if ( criterion == Email ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?person "
"WHERE { "
" graph ?g { "
" ?person <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?person a nco:PersonContact ; "
" nco:hasEmailAddress ?email . "
" ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . "
" } "
"}" );
} else if ( criterion == NickName ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:nickname ?v . "
" ?v bif:contains \"'%1'\" . "
" } "
"}" );
if ( match == ExactMatch ) {
if ( criterion == Name ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. "
" } "
"} " );
} else if ( criterion == Email ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?person "
"WHERE { "
" graph ?g { "
" ?person <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?person a nco:PersonContact ; "
" nco:hasEmailAddress ?email . "
" ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . "
" } "
"}" );
} else if ( criterion == NickName ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:nickname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ."
" } "
"}" );
} else if ( criterion == NameOrEmail ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" { ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>. } "
" UNION "
" { ?r nco:hasEmailAddress ?email . "
" ?email nco:emailAddress \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> . } "
" } "
"}" );
}
} else if ( match == StartsWithMatch ) {
if ( criterion == Name ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:fullname ?v . "
" ?v bif:contains \"'%1*'\" . "
" } "
"} " );
} else if ( criterion == Email ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?person "
"WHERE { "
" graph ?g { "
" ?person <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?person a nco:PersonContact ; "
" nco:hasEmailAddress ?email . "
" ?email nco:emailAddress ?v . "
" ?v bif:contains \"'%1*'\" . "
" } "
"}" );
} else if ( criterion == NickName ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:nickname ?v . "
" ?v bif:contains \"'%1*'\" . "
" } "
"}" );
} else if ( criterion == NameOrEmail ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" { ?r nco:fullname ?v . "
" ?v bif:contains \"'%1*'\" . } "
" UNION "
" { ?r nco:hasEmailAddress ?email . "
" ?email nco:emailAddress ?v . "
" ?v bif:contains \"'%1*'\" . } "
" } "
"}" );
}
} else if ( match == ContainsMatch ) {
if ( criterion == Name ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:fullname ?v . "
" ?v bif:contains \"'%1'\" . "
" } "
"} " );
} else if ( criterion == Email ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?person "
"WHERE { "
" graph ?g { "
" ?person <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?person a nco:PersonContact ; "
" nco:hasEmailAddress ?email . "
" ?email nco:emailAddress ?v . "
" ?v bif:contains \"'%1'\" . "
" } "
"}" );
} else if ( criterion == NickName ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" ?r nco:nickname ?v . "
" ?v bif:contains \"'%1'\" . "
" } "
"}" );
} else if ( criterion == NameOrEmail ) {
query += QString::fromLatin1(
"SELECT DISTINCT ?r "
"WHERE { "
" graph ?g { "
" ?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
" ?r a nco:PersonContact . "
" { ?r nco:fullname ?v . "
" ?v bif:contains \"'%1'\" . } "
" UNION "
" { ?r nco:hasEmailAddress ?email . "
" ?email nco:emailAddress ?v . "
" ?v bif:contains \"'%1'\" . } "
" } "
"}" );
}
}
if ( d->mLimit != -1 ) {
......
......@@ -98,16 +98,38 @@ class AKONADI_CONTACT_EXPORT ContactSearchJob : public ItemSearchJob
*/
enum Criterion
{
Name, ///< The name of the contact.
Email, ///< The email address of the contact.
NickName ///< The case-insensitive nickname of the contact
Name, ///< The name of the contact.
Email, ///< The email address of the contact.
NickName, ///< The nickname of the contact.
NameOrEmail ///< The name or email address of the contact. @since 4.5
};
/**
* Describes the type of pattern matching that shall be used.
*
* @since 4.5
*/
enum Match
{
ExactMatch, ///< The result must match exactly the pattern (case sensitive).
StartsWithMatch, ///< The result must start with the pattern (case insensitive).
ContainsMatch ///< The result must contain the pattern (case insensitive).
};
/**
* Sets the @p criterion and @p value for the search.
*
* @note ExactMatch is used for the matching.
*/
void setQuery( Criterion criterion, const QString &value );
/**
* Sets the @p criterion and @p value for the search with @p match.
*
* @since 4.5
*/
void setQuery( Criterion criterion, const QString &value, Match match );
/**
* Sets a @p limit on how many results will be returned by this search job.
* This is useful in situation where for example only the first search result is needed anyway,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment