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

Nepomuk

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

#include <Nepomuk/Query/Query>

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

Classes

class  RequestProperty
 

Public Types

enum  QueryFlag { NoQueryFlags = 0x0, NoResultRestrictions = 0x1, WithoutFullTextExcerpt = 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 Nepomuk::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.

WithoutFullTextExcerpt 

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

It might make sense to set this flag in case one has no need for excerpts and does not want to suffer the small performance penalty that comes from querying them

Definition at line 233 of file query.h.

enum Nepomuk::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 369 of file query.h.

Constructor & Destructor Documentation

Nepomuk::Query::Query::Query ( )

Create an empty invalid query object.

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

Create a query with root term term.

Nepomuk::Query::Query::Query ( const Query &  )

Copy constructor.

Nepomuk::Query::Query::~Query ( )

Destructor.

Member Function Documentation

void Nepomuk::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()
static Query Nepomuk::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
static Query Nepomuk::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
bool Nepomuk::Query::Query::fullTextScoringEnabled ( ) const
Returns
true if full text scoring has been enabled.
See also
setFullTextScoringEnabled()
Since
4.6
Qt::SortOrder Nepomuk::Query::Query::fullTextScoringSortOrder ( ) const
Returns
The full text scoring sort order as set via setFullTextScoringSortOrder()
Since
4.6
bool Nepomuk::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
bool Nepomuk::Query::Query::isValid ( ) const
Returns
true if the query is valid, i.e. it has a valid term().
int Nepomuk::Query::Query::limit ( ) const

The maximum number of results that this query should yield.

See also
setLimit()
int Nepomuk::Query::Query::offset ( ) const

The first result that should be retrieved.

See also
setOffset()
Since
4.5
bool Nepomuk::Query::Query::operator!= ( const Query &  query) const

Comparison operator.

Returns
true if this query differs from query.
Since
4.6
Query& Nepomuk::Query::Query::operator= ( const Query &  )

Assignment operator.

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

Assignment operator.

Assigns term to this query without changing any other properties.

Since
4.5
bool Nepomuk::Query::Query::operator== ( const Query &  query) const

Comparison operator.

Returns
true if this query is equal to query.
Query Nepomuk::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()
QueryFlags Nepomuk::Query::Query::queryFlags ( ) const

Get the query flags to configure this query.

See also
setQueryFlags()
Since
4.6
QList<RequestProperty> Nepomuk::Query::Query::requestProperties ( ) const
Returns
The list of RequestProperty instances set via addRequestProperty and setRequestProperties.
RequestPropertyMap Nepomuk::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().

void Nepomuk::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
void Nepomuk::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
void Nepomuk::Query::Query::setLimit ( int  )

Set the maximum number of results this query should yield.

See also
limit
void Nepomuk::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
void Nepomuk::Query::Query::setQueryFlags ( QueryFlags  flags)

Set the query flags to configure this query.

See also
queryFlags()
Since
4.6
void Nepomuk::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()
void Nepomuk::Query::Query::setTerm ( const Term &  )

Set the root term of the query.

See also
term
static QString Nepomuk::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
Term Nepomuk::Query::Query::term ( ) const

The root term of the query.

This can be any type of term.

See also
setTerm()
static QString Nepomuk::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
FileQuery Nepomuk::Query::Query::toFileQuery ( ) const
Returns
A copy of this query which is restricted to files.
Since
4.6
KUrl Nepomuk::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
KUrl Nepomuk::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
QString Nepomuk::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
QString Nepomuk::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

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

KDE's Doxygen guidelines are available online.

Nepomuk

Skip menu "Nepomuk"
  • 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