Query Class Reference
from PyKDE4.nepomuk import *
Namespace: Nepomuk.Query
Detailed Description
\class Query query.h Nepomuk/Query/Query
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.
\sa QueryParser, FileQuery
- Since:
- 4.4
Method Documentation
__init__ | ( | self ) |
Copy constructor.
__init__ | ( | self, | ||
Nepomuk.Query.Term | term | |||
) |
Create a query with root term term.
__init__ | ( | self, | ||
Nepomuk.Query.Query | a0 | |||
) |
Copy constructor.
addRequestProperty | ( | self, | ||
Nepomuk.Query.Query.RequestProperty | property | |||
) |
Add a property that should be reported with each search result.
- Parameters:
-
property The requested property.
ComparisonTerm.setVariableName() provides a more flexible (but also slightly more complicated) way to select additional results.
\sa setRequestProperties, requestProperties, ComparisonTerm.setVariableName()
bool fullTextScoringEnabled | ( | self ) |
- Returns:
- true if full text scoring has been enabled.
\sa setFullTextScoringEnabled()
- Since:
- 4.6
Qt::SortOrder fullTextScoringSortOrder | ( | self ) |
- Returns:
- The full text scoring sort order as set via setFullTextScoringSortOrder()
- Since:
- 4.6
bool isFileQuery | ( | self ) |
- Returns:
- true if this is a file query that will only return files and folders.
\sa FileQuery
- Since:
- 4.5
bool isValid | ( | self ) |
- Returns:
- true if the query is valid, i.e. it has a valid term().
int limit | ( | self ) |
The maximum number of results that this query should yield.
\sa setLimit()
int offset | ( | self ) |
The first result that should be retrieved.
\sa setOffset()
- Since:
- 4.5
bool operator != | ( | self, | ||
Nepomuk.Query.Query | query | |||
) |
Comparison operator.
- Returns:
- true if this query differs from query.
- Since:
- 4.6
bool operator == | ( | self, | ||
Nepomuk.Query.Query | query | |||
) |
Comparison operator.
- Returns:
- true if this query is equal to query.
Nepomuk.Query.Query optimized | ( | self ) |
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
\sa Term.optimized()
Nepomuk.Query.Query.QueryFlags queryFlags | ( | self ) |
Get the query flags to configure this query.
\sa setQueryFlags()
- Since:
- 4.6
[Nepomuk.Query.Query.RequestProperty] requestProperties | ( | self ) |
- Returns:
- The list of RequestProperty instances set via addRequestProperty and setRequestProperties.
{QString:Nepomuk.Types.Property} requestPropertyMap | ( | self ) |
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().
setFullTextScoringEnabled | ( | self, | ||
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.
\sa setFullTextScoringSortOrder(), Result.score()
- Since:
- 4.6
setFullTextScoringSortOrder | ( | self, | ||
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.
\sa setFullTextScoringEnabled()
- Since:
- 4.6
setLimit | ( | self, | ||
int | a0 | |||
) |
Set the maximum number of results this query should yield.
\sa limit
setOffset | ( | self, | ||
int | offset | |||
) |
The first result that should be retrieved. This can be combined with setLimit() to do paged results.
- Since:
- 4.5
setQueryFlags | ( | self, | ||
Nepomuk.Query.Query.QueryFlags | flags | |||
) |
Set the query flags to configure this query.
\sa queryFlags()
- Since:
- 4.6
setRequestProperties | ( | self, | ||
[Nepomuk.Query.Query.RequestProperty] | properties | |||
) |
Set the properties that should be reported with each search result.
- Parameters:
-
properties The requested properties.
ComparisonTerm.setVariableName() provides a more flexible (but also slightly more complicated) way to select additional results.
\sa addRequestProperty, requestProperties, ComparisonTerm.setVariableName()
setTerm | ( | self, | ||
Nepomuk.Query.Term | a0 | |||
) |
Set the root term of the query.
\sa term
Nepomuk.Query.Term term | ( | self ) |
The root term of the query. This can be any type of term.
\sa setTerm()
Nepomuk.Query.FileQuery toFileQuery | ( | self ) |
- Returns:
- A copy of this query which is restricted to files.
- Since:
- 4.6
KUrl toSearchUrl | ( | self, | ||
Nepomuk.Query.Query.SparqlFlags | flags=Nepomuk.Query.Query.NoFlags | |||
) |
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:
-
customTitle An 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.
- Parameters:
-
flags Optional 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.
\sa toSparqlQuery(), SparqlFlag
- Since:
- 4.5
KUrl toSearchUrl | ( | self, | ||
QString | customTitle, | |||
Nepomuk.Query.Query.SparqlFlags | flags=Nepomuk.Query.Query.NoFlags | |||
) |
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:
-
customTitle An 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.
- Parameters:
-
flags Optional 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.
\sa toSparqlQuery(), SparqlFlag
- Since:
- 4.5
QString toSparqlQuery | ( | self, | ||
Nepomuk.Query.Query.SparqlFlags | flags=Nepomuk.Query.Query.NoFlags | |||
) |
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:
-
flags Optional 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.)
\sa toString(), toSearchUrl(), SparqlFlag
QString toString | ( | self ) |
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().
\sa fromString(), toSparqlQuery()
- Since:
- 4.5
Static Method Documentation
Nepomuk.Query.Query fromQueryUrl | ( | KUrl | url | |
) |
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.
\sa sparqlFromQueryUrl()
- Since:
- 4.5
Nepomuk.Query.Query fromString | ( | QString | queryString | |
) |
Parse a Query that has been encoded as a string via toString().
- Warning:
- This method can NOT parse SPARQL syntax.
\sa toString()
- Since:
- 4.5
QString sparqlFromQueryUrl | ( | KUrl | url | |
) |
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.
\sa fromQueryUrl()
- Since:
- 4.5
QString titleFromQueryUrl | ( | KUrl | url | |
) |
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
Enumeration Documentation
QueryFlag |
A set of flags that influence the result of the query.
\sa setQueryFlags(), SparqlFlags
- Since:
- 4.6
- Enumerator:
-
NoQueryFlags = 0x0 NoResultRestrictions = 0x1 WithoutFullTextExcerpt = 0x2
SparqlFlag |
Aditional flags modifying the behaviour of toSparqlQuery() and toSearchUrl().
- Enumerator:
-
NoFlags = 0x0 CreateCountQuery = 0x1 HandleInverseProperties = 0x2 CreateAskQuery = 0x4