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

From KDE TechBase
No edit summary
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 16: Line 16:


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.  
<br>


=== Using the nepomuksearch:/ kioslave<br> ===
=== Using the nepomuksearch:/ kioslave<br> ===
Line 39: Line 37:
<pre>nepomuksearch:/?query=nepomuk
<pre>nepomuksearch:/?query=nepomuk
</pre>
</pre>
search for the word nepomuk in the file name, content, comment, or other indexed field<br>
search for the word nepomuk in the file name, content, comment, or other indexed field
<pre>nepomuksearch:/?query=contentSize&gt;1000KiB
<pre>nepomuksearch:/?query=contentSize&gt;1000KiB
</pre>
</pre>
Line 45: Line 43:
<pre>nepomuksearch:/?query=rating&lt;2 or rating&gt;8</pre><pre>nepomuksearch:/?query=-hasTag:nepomuk
<pre>nepomuksearch:/?query=rating&lt;2 or rating&gt;8</pre><pre>nepomuksearch:/?query=-hasTag:nepomuk
</pre>
</pre>
search for resources WITHOUT the tag nepomuk<br>
search for resources WITHOUT the tag nepomuk


==== SPARQL syntax ====
==== SPARQL syntax ====
Line 56: Line 54:
<pre>nepomuksearch:/?sparql=select ?r where { ?r nie:hasTag &lt;nepomuk:/nepomuk&gt; }
<pre>nepomuksearch:/?sparql=select ?r where { ?r nie:hasTag &lt;nepomuk:/nepomuk&gt; }
</pre>
</pre>
select all resources tagged with "nepomuk"<br>
select all resources tagged with "nepomuk"


{{Template:warning|Much of this search syntax (negation, size postfixes, SPARQL queries is only available in the GSoC soc-virtualfolders branch. It will be merged to trunk in time for 4.4. Other functionality is only available in trunk or in KDE >= 4.3}}
{{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.