Help:Search Templates
A search template is like a mini search engine that allows you to find sections which contain templates matching certain criteria.
Template calls in Povo look like this:
{{ Restaurant
| Cuisine = Italian
| MaximumPartySize = 12
| CreditCards = American Express, Visa
}}
These template calls are essentially tables of named data; each one has a set of name-value pairs. In this case, the template call represents a restaurant whose cuisine is Italian, which takes American Express and Visa, and which can seat a maximum of 12 people in a party.
Search templates can answer questions like "Show me every section using the Restaurant template where Cuisine is 'Italian'" or "Show me every section using the Restaurant template where MaximumPartySize is greater than 8 and CreditCards contains 'Visa' and Cuisine is either 'Italian', 'French' or 'Chinese'".
Search templates are basically just HTML forms, combined with logic for using the form settings to match template calls. This logic can either be placed directly on the input elements of the form, or can be expanded into separate "test" elements. If the logic for a particular criterion is very simple, it's easier to just include it on the element. If the logic is complicated, it can makes sense to pull it out into a "test" element.
A test has access to all the variables that were set in the form, as well as the variables passed into the template call that the test is currently evaluating. This is easier to see in an example.
Here's a very simple search template:
Party Size: <input name="MinimumPartySize" type="text" match="MinimumPartySize <= MaximumPartySize"/>
Credit Cards: <input name="AmericanExpress" type="checkbox" match="CreditCards contains 'American Express'"/> American Express
This is just a regular HTML form, but with the addition of a "match" attribute. The match attribute contains a boolean expression in
Lingua; a "boolean expression" is just a statement that evaluates to true or false. When the search template is used, each one of the matches will be executed against the set of name-value pairs from the template call.
In this search template, we have two input elements. The first is a text field that lets us establish the number of people in the party and ensure that the restaurant can seat that many. The second requires that the restaurant take American Express.
So, for example, if we had three sections, each of which had a different call to the Restaurant template:
===Rocco's===
{{ Restaurant
| Cuisine = Italian
| MaximumPartySize = 6
| CreditCards = American Express, Visa
}}
===Le Fromage===
{{ Restaurant
| Cuisine = French
| MaximumPartySize = 8
| CreditCards = Visa
}}
===Golden Dragon===
{{ Restaurant
| Cuisine = Chinese
| MaximumPartySize = 12
| CreditCards = American Express
}}
If we entered "8" into the search template under party size, and checked the American Express box, the search template would evaluate each template call using the logic in the match attributes. For Rocco's, the search template would check "MinimumPartySize <= MaximumPartySize"; here the MinimumPartySize is 8 from the search template, and the MaximumPartySize is 6, from the template call. Eight is not less than or equal to six, so this test fails, and the search template rejects Rocco's.
Next, the search template looks at Le Fromage. Here, the MaximumPartySize is 8, which is equal to the party size we requested, so this test passes. The search template now looks at the next match attribute, "CreditCards contains 'American Express'". CreditCards is just "Visa" for Le Fromage, so this test fails, and we reject Le Fromage.
Finally, we test Golden Dragon. 8 is less than 12, so our MinimumPartySize is less than or equal to our MaximumPartySize, and thus this test passes. CreditCards for Golden Dragon
does contain "American Express", and thus the second test also passes. Since all of our criteria have been met, Golden Dragon is a match, and will be included in the results of the search.
Writing a search template is great, but how will people find it? You can integrate your search template with Povo by associating it with sets of tags. Adding a "tags" element to the page will associate the search template with that set of tags. So, for example, our template above might be associated with the tag "restaurants":
Party Size: <input name="MinimumPartySize" type="text" match="MinimumPartySize <= MaximumPartySize"/>
Credit Cards: <input name="AmericanExpress" type="checkbox" match="CreditCards contains 'American Express'"/> American Express
<tags>restaurants</tags>
Now, when a user clicks on the tag "restaurants" in the tag brower, he or she will see this search template. Unlike regular pages, though, multiple "tags" elements are treated separately. For example, if our tags looked like:
Party Size: <input name="MinimumPartySize" type="text" match="MinimumPartySize <= MaximumPartySize"/>
Credit Cards: <input name="AmericanExpress" type="checkbox" match="CreditCards contains 'American Express'"/> American Express
<tags>restaurants</tags>
<tags>food,dining</tags>
<tags>nightlife,eats</tags>
Then our search template would only show up if the user picked "restaurants", or picked both "food"
and "dining", or picked "nightlife"
and "eats". If the use only picked "dining" or only picked "nightlife", our search template wouldn't show up, since we haven't matched
all the tags in each "tags" element.
When a search template is displayed to the user, there's a heading which prompts the user to expand the search template if it seems to be what they're looking for. You can specify this question with the #QUESTION directive. Much like #REDIRECT, you can place the question on the first line, and the rest of the line will be displayed to the user:
#QUESTION Are you looking for a restaurant?
Party Size: <input name="MinimumPartySize" type="text" match="MinimumPartySize <= MaximumPartySize"/>
Credit Cards: <input name="AmericanExpress" type="checkbox" match="CreditCards contains 'American Express'"/> American Express
<tags>restaurants</tags>
<tags>food,dining</tags>
<tags>nightlife,eats</tags>
Thank you for your contribution. You've taken a huge step to making Povo the "word on the street,"
and we appreciate it very much. Because of the complexity of the "wiki text" and code that can be used
on Povo, in order to edit this section in the future you must click the "edit" button to the right of the section
heading (or for the whole page).