Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paginating SPARQL results

Tags:

rdf

sparql

Suppose I have the following SPARQL query:

SELECT DISTINCT ?result ?label
WHERE {
  ?result a database:Column .
  ?result rdfs:label ?label .
}
ORDER BY (LCASE(?label))

What can I add to the query to limit the number of results to the first 10 given? Or preferably, the 10 results after the first n×10 results? I'm trying to implement pagination for visualizing the results.

like image 694
Xenyal Avatar asked Dec 15 '14 16:12

Xenyal


1 Answers

I'm trying to implement a system of paging for a table that visualizes the returned data.

You want to use limit, order by, and offset. They're described pretty well in the standard:

15.4 OFFSET

OFFSET causes the solutions generated to start after the specified number of solutions. An OFFSET of zero has no effect.

Using LIMIT and OFFSET to select different subsets of the query solutions will not be useful unless the order is made predictable by using ORDER BY.

15.5 LIMIT

The LIMIT clause puts an upper bound on the number of solutions returned. If the number of actual solutions, after OFFSET is applied, is greater than the limit, then at most the limit number of solutions will be returned.

In your case, your query would be something like this to show the fourth page of results when you are showing ten results per page:

SELECT DISTINCT ?result ?label
WHERE {
  ?result a database:Column .
  ?result rdfs:label ?label .
}
ORDER BY (LCASE(?label))
LIMIT 10
OFFSET 30
like image 109
Joshua Taylor Avatar answered Nov 10 '22 01:11

Joshua Taylor