Help:Selecting pages

The most important part of the Semantic search features in Semantic MediaWiki is a simple format for describing which pages should be displayed as the search result. Queries select wiki pages based on the information that has been specified for them using Categories, Properties, and maybe some other MediaWiki features such as a page's namespace. The following paragraphs introduce the main query features in SMW.



Preface
In the introductory example, we gave the single condition  to describe which pages we were interested in. The markup text is exactly what you would otherwise write to assert that some page has this property and value. Putting it in a semantic query makes SMW return all such pages. This is a general scheme: The syntax for asking for pages that satisfy some condition is exactly the syntax for explicitly asserting that this condition holds.

The following queries show what this means:
 * 1)   gives all pages directly or indirectly (through a sub-, subsub-, etc. category) in the category.
 * 2)   gives all pages  annotated as being about someone born in Boston.
 * 3)    gives all pages  annotated as being about someone having a height of 180cm.

By using other categories or properties than above, we can already ask for pages which have certain annotations. Next let us combine those requirements: Born in::Boston Height::180cm asks for everybody who is an actor and was born in Boston and is 180cm tall. In other words: when many conditions are written into one query, the result is narrowed down to those pages that meet all the requirements. Thus we have a logical AND. By the way: queries can also include line breaks in order to make them more readable. So we could as well write: Born in::Boston Height::180cm

to get the same result as above. Note that queries only return the articles that are positively known to satisfy the required properties: if there is no property for the height of some actor, that actor will not be selected.

When specifying property values, SMW will usually ignore any initial and trailing whitespace, so the two conditions  and   have the same meaning. Datatypes such as may have additional features such as ignoring commas that might be used to separate the thousands. SMW will also treat synonymous page names the same, just like MediaWiki would usually consider "Semantic wiki", "Semantic_wiki" and "semantic wiki" to refer to the same page.

If you are using certain condition patterns frequently, you might create a Concept as a shorthand. Concepts form some kind of virtual category and can thus be used similar to category conditions.

Search features

 * Search operators shows how to refine search conditions and criteria using operators such as comparators or wildcards.
 * Unions of results describes how disjunctions (OR-conditions) can be used to combine query results on alternative conditions.
 * Single page restriction section describes how to directly select some pages, or pages from a given namespace.
 * Specify range of pages
 * Use namespace restrictions
 * Subqueries and property chains
 * Work with value substitutions describes how templates and variables can be used in a query to substitute value components
 * Distance queries

Sorting results
It is often helpful to present query results in a suitable order, for example to present a list of cities ordered by population.

has a simple interface to add one or more sorting conditions to a query ... read more.

Linking to results
Links to semantic query results on Special:Ask can be created by means of the inline query feature in SMW as explained in its documentation. It is not recommended to create links directly, since they are very lengthy and use a specific encoding. Developers who create extensions that link to Special:Ask should also use SMW's internal functions for building links. Understanding the details of SMW's encoding of queries in links is therefore not required for using SMW.

Subqueries for properties
It is not possible to use a subquery to obtain a list of properties that is then used in a query. One can, however, use a query that returns a list of properties, and copy and paste the result into another query. Alternatively, one can use the template results format to pass properties directly to another query.

Querying for the absence of a property
It is not possible to query for the absence of a property. (talk). Depending of the structure of the wiki, a workaround may be possible.

Filtering Categories and Concepts
It is not possible to ask for all pages of a query that are not in a specific category or concept. For example, the query  will query every page in category "!City" instead of every page that is not in category "City". (talk)