Query

A way to search and filter the structure of a Silk site.

Site

Page

User

Taglist 

Query 

FAQ

Facts collected from tagged text on this page
Facts about this page

Introduction

We changed domains: please change any mentions of silkapp.com in the code examples to silk.co.

Silk lets you query tags in a site. Querying is a very powerful feature that lets you select, search and filter information. Queries are the basis of all visualisations within Silk.

To perform a query (for example, list all countries in the Caribbean), do this

We will update a complete reference to our query language shortly, in the meanwhile here is a primer. We also have a guide if you exactly want to know how to perform certain queries.

Query syntax

The query language that Silk uses has has a syntax that is explained below, lets look at this query (continued from the example above):

Where statement

Lets go through this query step by step. The query always begins with

from all documents 

To apply filter parameters, use the where clause (always use the complete url of the tag to refer to that tag)

where http://world.silk.co/tag/Region 

this line filters out results without a region tag

and (document has type http://world.silk.co/tag/Country)

the 'document has type ...' indicates to only select pages that have a specific category. You can select multiple categories.

and (http://world.silk.co/tag/Region is "Caribbean") 

this selects only the results that have 'Caribbean' as the value for the tag Region. It is also possible to add a contains (instead of is) operator to find results as 'Dutch Caribbean':

and (http://world.silk.co/tag/Region contains "Caribbean") 

for numeric values, it is possible to do greater than and less than to filter results:

and http://world.silk.co/tag/GDP%20Growth greater than "1" 

and http://world.silk.co/tag/GDP%20Growth less than "2"

This filters the results to have GDP growth between 1 and 2.

For linked tags (e.g. a head of state on a country page is linked to its own page which has category 'Head of state') you can use this syntax to filter, this example only shows countries for which the head of state is a king:

and (http://world.silk.co/tag/Title for http://world.silk.co/tag/Head%20of%20State is "King")

Select statement

The second part of the query selects the tags to be included in the response

select document name 

This indicates to include the document name in the response

and http://world.silk.co/tag/Region 

This indicates that the tag Region should be included in the response. You can add multiple lines to include more tags.

Sorting

The third part of the query is optional, namely sorting. Sorting can be done on only one tag or document name:

order ascending by document name

or

order descending by http://world.silk.co/tag/GDP%20Growth

Slicing

The final part of the query, also optional, is slicing the results

slice from 0 to 99

the above line makes sure only the outputs 0 to 99 are included in the output. Slicing lets you limit the number of results and makes pagination possible.

Query response

The response of the API call is an HTML table with the results, for example, the results of all countries in the Caribbean

The table not only includes the results, but also the type of results and geo-locations for example. Additionaly, in the <table> tag in the example above, it shows that the slice requested was from 0 - 99 and that there are 14 results.

Just like in the structure of pages, the output includes -data attributes that specify the type of data (numeric, geo, currency, textual).