Commit 909dc397 authored by Thomas McGuire's avatar Thomas McGuire

Add the ability to limit the number of search results.

CCBUG: 219687

svn path=/trunk/KDE/kdepimlibs/; revision=1081954
parent 7d2124f1
......@@ -25,10 +25,17 @@
using namespace Akonadi;
class ContactSearchJob::Private
{
public:
int mLimit;
};
ContactSearchJob::ContactSearchJob( QObject * parent )
: ItemSearchJob( QString(), parent ), d( 0 )
: ItemSearchJob( QString(), parent ), d( new Private() )
{
fetchScope().fetchFullPayload();
d->mLimit = -1;
// by default search for all contacts
ItemSearchJob::setQuery( QLatin1String( ""
......@@ -38,6 +45,7 @@ ContactSearchJob::ContactSearchJob( QObject * parent )
ContactSearchJob::~ContactSearchJob()
{
delete d;
}
void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
......@@ -62,6 +70,9 @@ void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
" }" );
}
if ( d->mLimit != -1 ) {
query += QString::fromLatin1( " LIMIT %1" ).arg( d->mLimit );
}
query = query.arg( value );
ItemSearchJob::setQuery( query );
......
......@@ -108,6 +108,17 @@ class AKONADI_CONTACT_EXPORT ContactSearchJob : public ItemSearchJob
*/
void setQuery( Criterion criterion, const QString &value );
/**
* 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,
* setting a limit of 1 here will greatly reduce the resource usage of Nepomuk during the
* search.
*
* This needs to be called before calling setQuery() to have an effect.
* By default, the number of results is unlimited.
*/
void setLimit( int limit );
/**
* Returns the contacts that matched the search criteria.
*/
......
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