Help:What can i do with the query interface?


 * Question
 * Question:=What can i do with the query interface?


 * Answer
 * description:=Use the QI to search the wiki, generate useful lists and tables containing facts from the knowledgebase.



Overview of the query interface
The query interface is a special page and can therefore be accessed on the page “Special:Specialpages”. When accessing this page, you can see the Query Interface (QI) in its initial state.



On the very bottom, there is the menu bar with the three main functions:
 * Preview query: A full preview of the current query, also considering the layout settings on bottom
 * Copy to clipboard: This button will copy the ask query to the clipboard. This will always work for Microsoft Internet Explorer Browsers. If you use Firefox, there might be a security question coming up. Depending on your local security settings, the “copy to clipboard” functionality will not be available at all.
 * Reset Query: This button will reset the current query and all its sub- and superqueries

On top of the query interface to the left, you can see the query tree with a breadcrumbs navigation and the tree graph. The breadcrumbs navigation shows where you are in the structure of your current query. The tree shows the structure of the query and allows you to navigate through it by clicking the single items.





In the middle of the QI, there is the main part of the interface where you can add further restrictions to your query. Right niext to this area, the context sensitive help is shown. For further information about context sensitive help, see Help:What_is_context_sensitive_help? Below the main area, you can see the table column preview. Most query results in SMW are shown in tables. This little window will give you an instant preview of which columns will appear in the result table of the current query. At the bottom, there is the query layout manager (QLM). The QLM supports you by defining the output format of your query, since there are many different possibilities.

Creating a sample query with the QI
This section of the user documentation will give a step by step example for creating a query with the QI. The example query used in this case is as follows:


 * “Give me the number of inhabitants for every European Union capital”

First of all, we have to define what we look for and according to this choose a category. Of course, this choice always depends on the content and structure of the wiki. In this example, we will say that capitals are in the category “city”. The first step therefore is that we ask for this category. In every input field of the QI you can use auto completion in order to find appropriate inputs.



After clicking “OK”, the category will appear in the query tree. For every capital, we want to have the number of inhabitants, which is a property. The next step therefore is to add this property to the query.

As we would like to have the number of inhabitants printed out in the result table, we have to check “Show in result table”. Please be reminded that only properties in the main part of the query can be printed. Properties of subqueries can not be printed, therefore this checkbox will not appear. As value we enter “*” for all values, but this field can as well stay empty which would have the same effect.

As stated in our query, we want only those cities that are capitals of countries which belong to the European Union. The word “which” is always a hint on a subquery. Therefore we have to create a subquery here.

To add a subquery, simple check the “Insert subquery” box next to the input field. Subqueries are only possible with properties that refer to another wiki page. If a property has for example Integer or Date as a type, subqueries are not possible.

Now, the subquery can be edited. This happens by clicking “Subquery 1” in the tree view. You will then see a new empty tree which represents the contents of the subquery. This subquery will search for all Countries that are part of the European Union. Therefore, we will have to add the category “Country” and the property “is part of” with the value “European Union”.

By clicking on “Main” on top of the treeview, you can navigate back to the main part of the query. Before finishing the query, some layout parameters will be set. As a format, we choose table. The main label is the heading of the first table column. We will call this one city. Finally, we want our results sorted by the number of inhabitants in an descending order.

By clicking on “Preview results”, the results of the current query can be checked. In this case, there are only two cities in the database which are Berlin and Rome. The query is now finished and can be copied to the clipboard for further use in other articles.

The query layout manager
This section will give a short overview of the query layout manager and the meaning of the single options.

Advanced usage: conjunction and disjunction
Whenever you add a category, instance or property they are connected by conjunction. This means that all entered restrictions have to be true in order to appear in the result table. However, sometimes it is necessary to use a disjunction. This can be done by using the green plus sign next to an input field.

The above image shows an example of disjunction. This query would return all articles that are either in the category book OR in the category movie. If you add one category Movie and one category book, conjunction is applied and the query would return only articles that are in both categories (for example “1984” by George Orwell, since this is a book as well as a movie).