Name | Type | Size | Values | Tooltip message | Attributes |
---|---|---|---|---|---|
MealName | text | 60 | The name of the recipe | ||
RecipePDF | file | maxsize{15000K} pattern{[a-z,A-Z 0-9 -_]{1,}} | |||
SpicesUsed | select+multi+values | 5 | Spice Search | Display all spices in my SpiceDB |
%SEARCH{ "name~'SpiceDB????'" type="query" nonoise="on" sort="formfield(SpiceName)" format="$formfield(SpiceName)" separator=", "}%Since we've mentioned the SpiceDB let's show the form: SpiceForm
Name | Type | Size | Values | Tooltip message | Attributes |
---|---|---|---|---|---|
SpiceName | text | 60 | The name of the spice | ||
SpiceInventory | text | 60 | The quantity of spice in inventory |
%SEARCH{ "name~'RecipeDB???'" type="query" nonoise="on" format="| [[%PUBURL%/%WEB%/$topic/$percntCALC{\"$LISTITEM($LISTSIZE($query(attachments.name)), $query(attachments.name))\"}$percnt][$formfield(MealName)]] | $formfield(SpicesUsed) | $percntSEARCH{\"name~'SpiceDB???' AND fields[name='SpiceName'].value='$formfield(SpicesUsed)'\" type=\"query\" nonoise=\"on\" format=\"[[$dollartopic][$dollarformfield(SpiceInventory)]]\"}$percnt | [[$topic][Edit]] | $percntCALC{$FORMATTIMEDIFF(1,min,$EVAL($TIME()-$query(info.date)))}$percnt ago |" header="| *Meal Name* | *Spices Required* | *Inventory* | *Edit Recipe* | *Last Updated* |" }%Breaking Down the Search Searches all topics starting with RecipeDB using a query search:
%SEARCH{ "name~'RecipeDB???'" type="query" nonoise="on"Display the MealName as a link to the latest attachment (by date). It uses $LISTSIZE to find the quantity of attachments in a topic and then requests the attachment with the highest index (which corresponds to the last attachment that was uploaded).
[[%PUBURL%/%WEB%/$topic/$percntCALC{\"$LISTITEM($LISTSIZE($query(attachments.name)), $query(attachments.name))\"}$percnt][$formfield(MealName)]]Display the value of the formfield named SpicesUsed for each topic
$formfield(SpicesUsed)Performs the nested search within each search hit for all topics starting with SpiceDB and having a form with a field called SpiceName that has a value matching the value of the formfield SpicesUsed in the parent search. The search then returns the inventory level of the spice and a link to the specific SpiceDB??? topic.
$percntSEARCH{\"name~'SpiceDB???' AND fields[name='SpiceName'].value='$formfield(SpicesUsed)'\" type=\"query\" nonoise=\"on\" format=\"[[$dollartopic][$dollarformfield(SpiceInventory)]]\"}$percntNote: The above search will not work if there are multiple values in the SpicesUsed field. Provide a link to each Recipe topic if editing is required:
[[$topic][Edit]]Provides a neat way of displaying when the recipe topic was last updated (uses SpreadSheetPlugin)
$percntCALC{$FORMATTIMEDIFF(1,min,$EVAL($TIME()-$query(info.date)))}$percnt ago
$SETHASH( name, key, value )
. This means that for every spice (key)in my collection I can store the inventory level matching that spice as the value.
%SEARCH{ "name~'SpiceDB????'" type="query" nonoise="on" format="$percntCALCULATE{$SETHASH(SpiceQty, $formfield(SpiceName), $formfield(SpiceInventory)) $SETHASH(SpiceTopic, $formfield(SpiceName), $topic)}$percnt }%Now, I have a hash created where, instead of doing a search for inventory level of a particular spice, I can simply call
$GETHASH(SpiceQty, Cinnamon)
and it will return 4 cups (which corresponds to my inventory level). I also have another hash created that can find out the topic of a particular spice by $GETHASH(SpiceTopic, Cinnamon)
which will return SpiceDB005.
The search command is then changed to:
%SEARCH{ "name~'RecipeDB???'" type="query" nonoise="on" format="| [[%PUBURL%/%WEB%/$topic/$percntCALC{\"$LISTITEM($LISTSIZE($query(attachments.name)), $query(attachments.name))\"}$percnt][$formfield(Part Number)]] | $percntCALCULATE{$LISTJOIN(<br>,$LISTEACH([[$GETHASH(SpiceTopic,$item)][$item]],$formfield(SpicesUsed))) | $LISTJOIN(<br>,$LISTEACH($GETHASH(ProgStatus,$item),$formfield(ProgramNumber)))}$percnt | [[$topic][Edit]] | $percntCALC{$FORMATTIMEDIFF(1,min,$EVAL($TIME()-$query(info.date)))}$percnt ago |" header="| *Meal Name* | *Spices Required* | *Inventory* | *Edit Recipe* | *Last Updated* |"}%Most of the content is identical to the search describe in the nested search example above so the focus will be only on what's different. Our goal here is to display the name of the spice, that when clicked, goes to the topic for that specific spice. We also want to display the inventory level of that particular spice. The structure is a bit more complicated because we need to be able to handle multiple spices for each recipe if needed. For example: the recipe for Pancakes may require the spices Cinnamon and Vanilla (displayed as Cinnamon, Vanilla in the formfield(SpicesUsed)).
$percntCALCULATE{$LISTJOIN(<br>,$LISTEACH([[$GETHASH(SpiceTopic,$item)][$item]],$formfield(SpicesUsed))) |
$LISTJOIN(<br>,takes a list that is separated by commas and replaces the comma with another character. In this case a line break.
$LISTEACH(takes a list and applies a formula to the list.
[[$GETHASH(SpiceTopic,$item)][$item]],$formfield(SpicesUsed)))takes the input list of
$formfield(SpicesUsed)
and applies a formula. In this case the formula is [[$GETHASH(SpiceTopic,$item)][$item]]
which uses the hash that accepts the name of the spice and returns the topic for that spice. The $GETHASH
portion provides the spice topic while $item
provides the name of the spice for the link. This formula is applied to each spice (or element ($item
)) in $formfield(SpicesUsed)
. This completes $LISTEACH
which provides a list such as Cinnamon, Vanilla, Nutmeg
The outer step is $LISTJOIN
which takes the comma separated list and replaces it with line breaks.
The next part of the search is identical to the previous with the exception that the formula does not create links for the inventory level.
$LISTJOIN(<br>,$LISTEACH($GETHASH(SpiceQty,$item),$formfield(SpicesUsed)))}$percnt
Meal Name | Spices Required | Inventory | Edit Recipe | Last Updated |
---|---|---|---|---|
Pancakes | Cinnamon Vanilla Nutmeg |
4 cups 10 sticks 45 grams |
Edit | 10 days ago |
Chili | Paprika | 50 grams | Edit | 10 hours ago |
Lentil Soup | Coriander Thyme |
10 grams 20 grams |
Edit | 5 hours ago |