Advanced Page Queries

ProWiki | RecentChanges | Preferences

Previous: Inheritance

Okay -- now that we've laid out the groundwork, let's talk about some of the more advanced features of the query language.

Inheritance Queries

One of the most useful kinds of query is the inheritance query. This is a special kind of page query, that says, "Show me all the pages that descend from this type". An inheritance query looks just like any other page query, except for one major tweak: you put a "~" in front of the query string, to indicate that you are looking for inheritance instead of properties.

For example, let's look at The Incredibly Dippy Subway Game. This contains many characters of different classes -- that is, each character has an IS_A property that points to the character's class. One of those classes is "Loiterers". To list all of the Loiterers in the game, you give this query:

{?~Loiterer : <b>%%Name%%</b> (<i>%%PAGENAME%%</i>)<br>?}

That is, "For each page that inherits from Loiterer, show me the Name and PAGENAME of that page." It shows up like this:

A bag lady (Bag Lady)
Guy With a Guitar (GuitarGuy)
A skateboard punk (Skateboard Punk)

This is one of the most powerful queries in ProWiki, because it lets you make lists of objects very easily. If most of the pages in your Wiki are typed objects, then it's trivial to make pages that list them in all sorts of different ways.

Combining Query Clauses

Now let's make that even more powerful. All of the page queries shown so far simply give a single "word" as the query string. But in fact, ProWiki allows you to combine multiple query clauses to get more refined queries.

The best way to understand this is to think of a query as reading from left to right. Each clause defines a set of pages, which are then combined using conjunctions to get the final result. There are three kinds of conjunctions available:

For a simple example, let's look at the Subway Game again. There are two major kinds of Characters in the game, Passengers and Loiterers. But there are a few Characters who don't fall into either of those categories. To list just the Characters who are neither Passengers nor Loiterers, we would say:

{?~Character &! ~Passenger &! ~Loiterer : <b>%%Name%%</b> (<i>%%PAGENAME%%</i>)<br> ?}

That is, "Show me all pages that inherit from Character, and do not inherit from Passenger, and do not inherit from Loiterer". That displays as:

Musician (Musician)
A security guard (Security Guard)

You aren't restricted to inheritance queries in this. For example, the following

{?~Character && Item : <b>%%Name%%</b> (<i>%%PAGENAME%%</i>)<br> ?}

Says, "Show me all the pages that inherit from Character and have at least one Item property." It shows up as:

A bag lady (Bag Lady)
A Bank Customer (BankCustomer)
Businessman (Businessman)
A father (Father)
Guy With a Guitar (GuitarGuy)
A Mother (Mother)
Musician (Musician)
A security guard (Security Guard)
A skateboard punk (Skateboard Punk)

Neat, huh? Using this mechanism, you can construct almost arbitrarily complex queries.

Nesting Property Lists Inside Page Queries

Okay, one last trick before we conclude. You've seen both Page Queries and Property Lists. What you haven't seen so far is that these can be combined.

A Property List, as mentioned before, means "Show me all of this kind of property on this page". But "this page" isn't limited to the page that you're looking at right now. If a Property List shows up inside a Page Query, "this page" refers to the current page in the query.

Let's illustrate this with the fanciest query in the Subway Game: the packing list. To keep it short, we'll show just a subset of the game. This query:

{?~Loiterer : <b>%%Name%%</b> (<i>%%PAGENAME%%</i>): {*Item :
* <b>%%Item.Name%%</b> (<i>%%Item.PAGENAME%%</i>)*}<br>
?}

That's quite a mouthful. It translates as, "For each Loiterer, give the Name of the Loiterer, then list all of their Items". Note that the pattern for each Item starts on a new line -- that's so that the asterisk (which in Wiki-speak means "bullet list item") shows up at the beginning of the line and turns into a bullet. Finally, there's a last line-break at the end, after the list of items, to neatly separate each Loiterer. Putting that into action, we see it like this:

{?~Loiterer : (Advanced Page Queries):
?}

Conclusion

That's the whole system. (Or most of it, anyway -- there are a few experimental features that don't work as well yet, so they aren't covered here.) Try it out, and see what you get. While I'll grant that it isn't the simplest system in the world, it's extremely powerful, and lets you organize your data very easily once you get the hang of it.

Back to the ProWiki homepage


ProWiki | RecentChanges | Preferences
This page is read-only | View other revisions | View source of this page
Last edited May 19, 2005 6:32 pm by Jducoeur
Search:
Edit: