Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

rdf - Paginating SPARQL results

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...