Development/Tutorials/Metadata/Nepomuk/QueryService: Difference between revisions

From KDE TechBase
mNo edit summary
mNo edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 5: Line 5:
next=|
next=|
reading=[[../NepomukServices|Nepomuk Services]], [[../NepomukServer|Nepomuk Server]]|
reading=[[../NepomukServices|Nepomuk Services]], [[../NepomukServer|Nepomuk Server]]|
}}
}}  


==Nepomuk Query Service==
== Nepomuk Query Service ==


The Query service provides a D-Bus interfaces named ''org.kde.nepomuk.QueryService'' which is exported at ''nepomukqueryservice''. This interface allows to issue queries using a simple user language (most importantly one can use ''AND'' and ''OR'' to combine terms and ''field:value'' terms to query certain fields. In the latter case ''value'' will be matched to a literal value or the label of a resource in case the property matching ''field'' has a non-literal range.)
The Query service provides a D-Bus interfaces named ''org.kde.nepomuk.QueryService'' which is exported at ''nepomukqueryservice''. This interface allows to issue queries using a simple user language (most importantly one can use ''AND'' and ''OR'' to combine terms and ''field:value'' terms to query certain fields. In the latter case ''value'' will be matched to a literal value or the label of a resource in case the property matching ''field'' has a non-literal range.)  


Calling the ''query'' method will return the path to a new D-Bus object which provides the interface ''org.kde.nepomuk.Query''. The latter interface allows to list the results and emits signals for new or removed results.
Calling the ''query'' method will return the path to a new D-Bus object which provides the interface ''org.kde.nepomuk.Query''. The latter interface allows to list the results and emits signals for new or removed results.  


Normally one would use the ''libnepomukqueryclient'' library provided by ''kdebase/workspace'' to access this services.
Normally one would use the ''libnepomukqueryclient'' library provided by ''kdebase/workspace'' to access this services.  


Another possibility is the Nepomuk Query KIO slave named ''nepomuksearch''. This will return results formatted as UDSEntries.
Another possibility is the Nepomuk Query KIO slave named ''nepomuksearch''. This will return results formatted as UDSEntries.  
 
=== Using the nepomuksearch:/ kioslave<br> ===
 
There are two search types available: the simple query syntax and a method to directly open SPARQL queries.<br>The legacy search method is to simply open
<pre>nepomuksearch:/&lt;simple search query&gt;</pre>
This is deprecated. Instead, to open a simple query you should open
<pre>nepomuksearch:/?query=&lt;simple search query&gt;</pre>
and to open a SPARQL query you should open
<pre>nepomuksearch:/?sparql=&lt;sparql query&gt;
</pre>
==== Simple Search Syntax ====
 
The search syntax in Dolphin is as follows:<br>expression logicop...<br>logicop = and | or<br>expression = text | negation field operand value<br>operand = : | = | &gt; | &lt; | &lt;= | &gt;=<br>field: any ontology property<br>negation: + | -
 
The negation term is positive if unspecified.
 
Field refers to any ontology properties. Some common properties:<br>lastModified: resource modification date<br>contentSize: resource size<br>artist, album, title, year, genre, trackNumber, discNumber: music metadata<br>hasTag: search by tag<br>mimeType<br>fileExtension<br>rating: a 1 - 10 rating
 
===== Some examples: =====
<pre>nepomuksearch:/?query=nepomuk
</pre>
search for the word nepomuk in the file name, content, comment, or other indexed field
<pre>nepomuksearch:/?query=contentSize&gt;1000KiB
</pre>
search for resources with a size greater than 1000KiB. Supported size postfixes: KB, KiB, MB, MiB, GB, GiB, TB, TiB. These are case sensitive
<pre>nepomuksearch:/?query=rating&lt;2 or rating&gt;8</pre><pre>nepomuksearch:/?query=-hasTag:nepomuk
</pre>
search for resources WITHOUT the tag nepomuk
 
==== SPARQL syntax ====
 
Opening a SPARQL query is as simple as opening the URL
<pre>nepomuksearch:/?sparql=&lt;sparql query&gt;</pre>
The sparql query should have the variable ?r as one of the select variables. Simple ontology prefixes are possible: nie, nfo, rdf, rdfs, nrl, nao, xsd, pimo.
 
===== Examples: =====
<pre>nepomuksearch:/?sparql=select ?r where { ?r nie:hasTag &lt;nepomuk:/nepomuk&gt; }
</pre>
select all resources tagged with "nepomuk"
 
{{Note|Much of this search functionality is only available in the GSoC soc-virtualfolders branch. It will be merged to trunk in time for 4.4.}}

Latest revision as of 00:05, 18 August 2009

Nepomuk Query Service
Tutorial Series   Nepomuk
Previous   Strigi Service
What's Next  
Further Reading   Nepomuk Services, Nepomuk Server

Nepomuk Query Service

The Query service provides a D-Bus interfaces named org.kde.nepomuk.QueryService which is exported at nepomukqueryservice. This interface allows to issue queries using a simple user language (most importantly one can use AND and OR to combine terms and field:value terms to query certain fields. In the latter case value will be matched to a literal value or the label of a resource in case the property matching field has a non-literal range.)

Calling the query method will return the path to a new D-Bus object which provides the interface org.kde.nepomuk.Query. The latter interface allows to list the results and emits signals for new or removed results.

Normally one would use the libnepomukqueryclient library provided by kdebase/workspace to access this services.

Another possibility is the Nepomuk Query KIO slave named nepomuksearch. This will return results formatted as UDSEntries.

Using the nepomuksearch:/ kioslave

There are two search types available: the simple query syntax and a method to directly open SPARQL queries.
The legacy search method is to simply open

nepomuksearch:/<simple search query>

This is deprecated. Instead, to open a simple query you should open

nepomuksearch:/?query=<simple search query>

and to open a SPARQL query you should open

nepomuksearch:/?sparql=<sparql query>

Simple Search Syntax

The search syntax in Dolphin is as follows:
expression logicop...
logicop = and | or
expression = text | negation field operand value
operand = : | = | > | < | <= | >=
field: any ontology property
negation: + | -

The negation term is positive if unspecified.

Field refers to any ontology properties. Some common properties:
lastModified: resource modification date
contentSize: resource size
artist, album, title, year, genre, trackNumber, discNumber: music metadata
hasTag: search by tag
mimeType
fileExtension
rating: a 1 - 10 rating

Some examples:
nepomuksearch:/?query=nepomuk

search for the word nepomuk in the file name, content, comment, or other indexed field

nepomuksearch:/?query=contentSize>1000KiB

search for resources with a size greater than 1000KiB. Supported size postfixes: KB, KiB, MB, MiB, GB, GiB, TB, TiB. These are case sensitive

nepomuksearch:/?query=rating<2 or rating>8
nepomuksearch:/?query=-hasTag:nepomuk

search for resources WITHOUT the tag nepomuk

SPARQL syntax

Opening a SPARQL query is as simple as opening the URL

nepomuksearch:/?sparql=<sparql query>

The sparql query should have the variable ?r as one of the select variables. Simple ontology prefixes are possible: nie, nfo, rdf, rdfs, nrl, nao, xsd, pimo.

Examples:
nepomuksearch:/?sparql=select ?r where { ?r nie:hasTag <nepomuk:/nepomuk> }

select all resources tagged with "nepomuk"

Note
Much of this search functionality is only available in the GSoC soc-virtualfolders branch. It will be merged to trunk in time for 4.4.