• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • Nepomuk2
  • Query
  • Query
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Nepomuk2::Query::Query Class Reference

#include <Nepomuk2/Query/Query>

Inheritance diagram for Nepomuk2::Query::Query:
Inheritance graph
[legend]

Classes

class  RequestProperty
 

Public Types

enum  QueryFlag { NoQueryFlags = 0x0, NoResultRestrictions = 0x1, WithFullTextExcerpt = 0x2 }
 
enum  SparqlFlag { NoFlags = 0x0, CreateCountQuery = 0x1, HandleInverseProperties = 0x2, CreateAskQuery = 0x4 }
 

Public Member Functions

 Query ()
 
 Query (const Term &term)
 
 Query (const Query &)
 
 ~Query ()
 
void addRequestProperty (const RequestProperty &property)
 
bool fullTextScoringEnabled () const
 
Qt::SortOrder fullTextScoringSortOrder () const
 
bool isFileQuery () const
 
bool isValid () const
 
int limit () const
 
int offset () const
 
bool operator!= (const Query &query) const
 
Query & operator= (const Query &)
 
Query & operator= (const Term &term)
 
bool operator== (const Query &query) const
 
Query optimized () const
 
QueryFlags queryFlags () const
 
QList< RequestProperty > requestProperties () const
 
RequestPropertyMap requestPropertyMap () const
 
void setFullTextScoringEnabled (bool enabled)
 
void setFullTextScoringSortOrder (Qt::SortOrder order)
 
void setLimit (int)
 
void setOffset (int offset)
 
void setQueryFlags (QueryFlags flags)
 
void setRequestProperties (const QList< RequestProperty > &properties)
 
void setTerm (const Term &)
 
Term term () const
 
FileQuery toFileQuery () const
 
KUrl toSearchUrl (SparqlFlags flags=NoFlags) const
 
KUrl toSearchUrl (const QString &customTitle, SparqlFlags flags=NoFlags) const
 
QString toSparqlQuery (SparqlFlags flags=NoFlags) const
 
QString toString () const
 

Static Public Member Functions

static Query fromQueryUrl (const KUrl &url)
 
static Query fromString (const QString &queryString)
 
static QString sparqlFromQueryUrl (const KUrl &url)
 
static QString titleFromQueryUrl (const KUrl &url)
 

Detailed Description

A Nepomuk desktop query.

A Query consists or a combination of Terms that can be optionally restricted via a limit (setLimit()) or folder filters (setIncludeFolders() and setExcludeFolders()).

Additionally setRequestProperties() allows to retrieve additional information about the results.

Queries can be easily converted to SPARQL via the toSparqlQuery() method or to search URLs ready for KIO::DirLister using toSearchUrl().

The typical usage of a Query instance would be QueryServiceClient::query(). However one can also use toSparqlQuery() to convert it into a SPARQL query string and use that string in QueryServiceClient::sparqlQuery() or even directly in Soprano::Model::executeQuery() via ResourceManager::instance()->mainModel() or in a custom Model.

See also
QueryParser, FileQuery
Author
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org
Since
4.4

Definition at line 76 of file query.h.

Member Enumeration Documentation

enum Nepomuk2::Query::Query::QueryFlag

A set of flags that influence the result of the query.

See also
setQueryFlags(), SparqlFlags
Since
4.6
Enumerator
NoQueryFlags 

No flags set.

This is the default.

NoResultRestrictions 

By default queries that will only return results which are intended for the user's eyes.

In situations where an application needs to work on internal or statistical data this restriction is not desireable. This flag disables the restriction and returns the full set of results.

WithFullTextExcerpt 

Enables the return of full text search excerpts for ComparisonTerm::Contains terms which are normally reported through Result::excerpt().

There is a very small performance penalty that comes from querying them.

Definition at line 233 of file query.h.

enum Nepomuk2::Query::Query::SparqlFlag

Aditional flags modifying the behaviour of toSparqlQuery() and toSearchUrl().

Enumerator
NoFlags 

No flags, i.e.

create a default query.

CreateCountQuery 

Create a SPARQL count query which will return the number of results rather than the results themselves.

The resuling query will have a single binding called 'cnt'.

HandleInverseProperties 

Automatically handle inverse properties, consider for example nie:isPartOf and nie:hasPart at the same time and even if only one of both is defined.

CreateAskQuery 

Create a SPARQL ask query which will simply check if a matching result exists.

Use Soprano::QueryResultIterator::boolValue() to check the result.

Since
4.6

Definition at line 368 of file query.h.

Constructor & Destructor Documentation

Nepomuk2::Query::Query::Query ( )

Create an empty invalid query object.

Definition at line 237 of file query.cpp.

Nepomuk2::Query::Query::Query ( const Term &  term)
explicit

Create a query with root term term.

Definition at line 249 of file query.cpp.

Nepomuk2::Query::Query::Query ( const Query &  other)

Copy constructor.

Definition at line 243 of file query.cpp.

Nepomuk2::Query::Query::~Query ( )

Destructor.

Definition at line 256 of file query.cpp.

Member Function Documentation

void Nepomuk2::Query::Query::addRequestProperty ( const RequestProperty &  property)

Add a property that should be reported with each search result.

Parameters
propertyThe requested property.

ComparisonTerm::setVariableName() provides a more flexible (but also slightly more complicated) way to select additional results.

See also
setRequestProperties, requestProperties, ComparisonTerm::setVariableName()

Definition at line 365 of file query.cpp.

Nepomuk2::Query::Query Nepomuk2::Query::Query::fromQueryUrl ( const KUrl &  url)
static

Extract a query from a nepomuksearch:/ query URL.

Returns
The query that was encoded in url or an invalid query if either url is not a nepomuksearch:/ URL or if it contains a pure SPARQL query. In the latter case sparqlFromQueryUrl() can be used to extract that query.
See also
sparqlFromQueryUrl()
Since
4.5

Definition at line 634 of file query.cpp.

Nepomuk2::Query::Query Nepomuk2::Query::Query::fromString ( const QString &  queryString)
static

Parse a Query that has been encoded as a string via toString().

Warning
This method can NOT parse SPARQL syntax.
See also
toString()
Since
4.5

Definition at line 610 of file query.cpp.

bool Nepomuk2::Query::Query::fullTextScoringEnabled ( ) const
Returns
true if full text scoring has been enabled.
See also
setFullTextScoringEnabled()
Since
4.6

Definition at line 341 of file query.cpp.

Qt::SortOrder Nepomuk2::Query::Query::fullTextScoringSortOrder ( ) const
Returns
The full text scoring sort order as set via setFullTextScoringSortOrder()
Since
4.6

Definition at line 347 of file query.cpp.

bool Nepomuk2::Query::Query::isFileQuery ( ) const
Returns
true if this is a file query that will only return files and folders.
See also
FileQuery
Since
4.5

Definition at line 281 of file query.cpp.

bool Nepomuk2::Query::Query::isValid ( ) const
Returns
true if the query is valid, i.e. it has a valid term().

Definition at line 275 of file query.cpp.

int Nepomuk2::Query::Query::limit ( ) const

The maximum number of results that this query should yield.

See also
setLimit()

Definition at line 299 of file query.cpp.

int Nepomuk2::Query::Query::offset ( ) const

The first result that should be retrieved.

See also
setOffset()
Since
4.5

Definition at line 305 of file query.cpp.

bool Nepomuk2::Query::Query::operator!= ( const Query &  query) const

Comparison operator.

Returns
true if this query differs from query.
Since
4.6

Definition at line 396 of file query.cpp.

Nepomuk2::Query::Query & Nepomuk2::Query::Query::operator= ( const Query &  other)

Assignment operator.

Definition at line 261 of file query.cpp.

Nepomuk2::Query::Query & Nepomuk2::Query::Query::operator= ( const Term &  term)

Assignment operator.

Assigns term to this query without changing any other properties.

Since
4.5

Definition at line 268 of file query.cpp.

bool Nepomuk2::Query::Query::operator== ( const Query &  query) const

Comparison operator.

Returns
true if this query is equal to query.

Definition at line 383 of file query.cpp.

Nepomuk2::Query::Query Nepomuk2::Query::Query::optimized ( ) const

Optimizes the query without chaning its meaning.

This removes redundant terms such as NegationTerm and OptionalTerm nestings and flattens AndTerm and OrTerm hierarchies.

Returns
An optimized version of this query.
Since
4.6
See also
Term::optimized()

Definition at line 601 of file query.cpp.

Nepomuk2::Query::Query::QueryFlags Nepomuk2::Query::Query::queryFlags ( ) const

Get the query flags to configure this query.

See also
setQueryFlags()
Since
4.6

Definition at line 359 of file query.cpp.

QList< Nepomuk2::Query::Query::RequestProperty > Nepomuk2::Query::Query::requestProperties ( ) const
Returns
The list of RequestProperty instances set via addRequestProperty and setRequestProperties.

Definition at line 377 of file query.cpp.

Nepomuk2::Query::RequestPropertyMap Nepomuk2::Query::Query::requestPropertyMap ( ) const

Build a request property map as used in QueryServiceClient::sparqlQuery() from the request properties set via addRequestProperty() and setRequestProperties().

Be aware that in most situations it is much simpler to use QueryServiceClient::query().

Definition at line 585 of file query.cpp.

void Nepomuk2::Query::Query::setFullTextScoringEnabled ( bool  enabled)

Nepomuk supports scoring the results based on any full text matching used in the query (full text matching is done via ComparisonTerm with the ComparisonTerm::Contains comperator) and sorting the results based on that score.

By default full text scoring is disabled since it can mean a serious impact on query performance.

See also
setFullTextScoringSortOrder(), Result::score()
Since
4.6

Definition at line 329 of file query.cpp.

void Nepomuk2::Query::Query::setFullTextScoringSortOrder ( Qt::SortOrder  order)

Set the full text scoring sort order.

Ignored if full text scoring is disabled.

By default the sort order is Qt::DescendingOrder.

See also
setFullTextScoringEnabled()
Since
4.6

Definition at line 335 of file query.cpp.

void Nepomuk2::Query::Query::setLimit ( int  limit)

Set the maximum number of results this query should yield.

See also
limit

Definition at line 317 of file query.cpp.

void Nepomuk2::Query::Query::setOffset ( int  offset)

The first result that should be retrieved.

This can be combined with setLimit() to do paged results.

Since
4.5

Definition at line 323 of file query.cpp.

void Nepomuk2::Query::Query::setQueryFlags ( QueryFlags  flags)

Set the query flags to configure this query.

See also
queryFlags()
Since
4.6

Definition at line 353 of file query.cpp.

void Nepomuk2::Query::Query::setRequestProperties ( const QList< RequestProperty > &  properties)

Set the properties that should be reported with each search result.

Parameters
propertiesThe requested properties.

ComparisonTerm::setVariableName() provides a more flexible (but also slightly more complicated) way to select additional results.

See also
addRequestProperty, requestProperties, ComparisonTerm::setVariableName()

Definition at line 371 of file query.cpp.

void Nepomuk2::Query::Query::setTerm ( const Term &  term)

Set the root term of the query.

See also
term

Definition at line 311 of file query.cpp.

QString Nepomuk2::Query::Query::sparqlFromQueryUrl ( const KUrl &  url)
static

Extract the SPARQL query from a nepomuksearch:/ query URL.

All kinds of nepomuksearch:/ URLs are supported.

Returns
The SPARQL query string representing the query encoded in url.
See also
fromQueryUrl()
Since
4.5

Definition at line 656 of file query.cpp.

Nepomuk2::Query::Term Nepomuk2::Query::Query::term ( ) const

The root term of the query.

This can be any type of term.

See also
setTerm()

Definition at line 293 of file query.cpp.

QString Nepomuk2::Query::Query::titleFromQueryUrl ( const KUrl &  url)
static

Extact the title from a nepomuksearch:/ query URL.

The title is either a custom title which has been specified in toSearchUrl(const QString&, SparqlFlags) or the user query string in case of nepomuksearch:/myquery URLs.

Returns
A title for the query url or an empty string in case url is not a nepomuksearch:/ URL or a useful title cannot be extracted.
Since
4.5

Definition at line 680 of file query.cpp.

Nepomuk2::Query::FileQuery Nepomuk2::Query::Query::toFileQuery ( ) const
Returns
A copy of this query which is restricted to files.
Since
4.6

Definition at line 287 of file query.cpp.

KUrl Nepomuk2::Query::Query::toSearchUrl ( SparqlFlags  flags = NoFlags) const

Convert the query into a URL which can be listed using KIO::DirLister.

The URL will use the nepomuksearch:/ KIO protocol to handle the listing of search results.

Parameters
flagsOptional flags to change the query. Query::CreateCountQuery is not supported and will silently be dropped from flags.
Returns
A URL which will list a virtual folder containing all search results from this query or an invalid URL in case this query is invalid.
See also
toSparqlQuery(), SparqlFlag

Definition at line 544 of file query.cpp.

KUrl Nepomuk2::Query::Query::toSearchUrl ( const QString &  customTitle,
SparqlFlags  flags = NoFlags 
) const

Convert the query into a URL which can be listed using KIO::DirLister.

The URL will use the nepomuksearch:/ KIO protocol to handle the listing of search results.

This is the perfect method for listing results in file managers or file dialogs.

Parameters
customTitleAn optional custom title that will be used for the listing of the results. This is achieved by setting the KIO::UDSEntry::UDS_DISPLAY_NAME to the customTitle value.
flagsOptional flags to change the query. Query::CreateCountQuery is not supported and will silently be dropped from flags.
Returns
A URL which will list a virtual folder containing all search results from this query or an invalid URL in case this query is invalid.
See also
toSparqlQuery(), SparqlFlag
Since
4.5

Definition at line 554 of file query.cpp.

QString Nepomuk2::Query::Query::toSparqlQuery ( SparqlFlags  flags = NoFlags) const

Convert the query into a SPARQL query which can be used with the Nepomuk query service or directly in Soprano::Model::executeQuery.

It is recommended to use QueryServiceClient instead of creating the SPARQL query this way.

The resulting query will bind the results to variable 'r'. Request properties will be bound to variables 'reqProp1' through 'reqPropN' (the only exception is a count query created via the CreateCountQuery flag).

If you are looking for a serialization of a Query which can be parsed again use toString() instead.

Warning
The SPARQL queries created by this method contain SPARQL extensions from Virtuoso and will not work with other RDF storage solutions!
Parameters
flagsOptional flags to change the query.
Returns
The SPARQL representation of this query or an empty string if the query could not be converted (invalid query.)
See also
toString(), toSearchUrl(), SparqlFlag

Definition at line 409 of file query.cpp.

QString Nepomuk2::Query::Query::toString ( ) const

Encode the Query in a string.

Be aware that this does NOT create a SPARQL query. The returned string can be used to serialize queries that can later be read via fromString().

See also
fromString(), toSparqlQuery()
Since
4.5

Definition at line 595 of file query.cpp.


The documentation for this class was generated from the following files:
  • query.h
  • query.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal