Tags:
search2Add my vote for this tag create new tag
view all tags
ALERT! NOTE: This is a SupplementalDocument topic which is not included with the official TWiki distribution. Please help maintain high quality documentation by fixing any errors or incomplete content. Put questions and suggestions concerning the documentation of this topic in the comments section below! Use the Support web for problems you are having using TWiki.

QuerySearch Pattern Cookbook

We have the very useful SearchPatternCookbook for regular expression searches. This topic provides tips on the usage of QuerySearch, a major leap in creating searches and available from TWiki 4.2.

Pattern 1: Show recent changes without user pages

We have everything in the Main web. But the updates to the personal pages are not that interesting to others, so we want to remove these.

We are looking for any page that does not have a form field "FirstName":

<dl>
%SEARCH{
"name~'*' AND NOT FirstName"
web="Main"
excludetopic="Web*,PersonalInfo,TWikiUsers"
type="query"
reverse="on"
limit="15"
order="modified"
nonoise="on"
format="<dt>[[$web.$topic][$topic(25,...)]]<br /><span class='twikiGrayText twikiSmall'>$date - <nop>$wikiname</span></dt>"
}%
</dl>

Pattern 2: List the 5 most recent blog post comments

The simple BlogAddOn has 1 comment topic that gathers all comments on the blog post. It has no TWiki Form (the blog post has one: BlogPostForm); the topic title is the name of the blog post + "Comments". How can we show the latest 5 comments?

We are looking for a topic with the title "xxxxComments". It has a parent and the parent has a form named "BlogPostForm":

<dl>
%SEARCH{
"name~'*Comments' AND (parent.name/(form.name='BlogPostForm')).value"
web="Main"
type="query"
limit="15"
reverse="on"
order="modified"
nonoise="on"
format="<dt>[[$web.$parent#BlogPostPrompt][$parent(30,...)]] ($rev)<br /><span class='twikiGrayText twikiSmall'>$date - <nop>$wikiname</span></dt>"
}%
</dl>

Pattern 3: Search named form fields using interactive user-input text

The code below searches through (two) named fields in all topics having the form 'MyPageForm'. A user search-form has input boxes for the search strings. The page calls itself recursively with results output to a table. The 'lc()' function forces case-insensitive lower case matching.

<noautolink> 
<form>
action="%SCRIPTURLPATH{view}%/%INCLUDINGWEB%/%INCLUDINGTOPIC%">
Field One: <input type="text" name="search_field_one" value="%URLPARAM{ "search_field_one" encode="entity" }%" size="15" /><br />
Field Two: <input type="text" name="search_field_two" value="%URLPARAM{ "search_field_two" encode="entity" }%" size="15" /><br />
<input type="submit" name="search_submit" value="Search">
</form>
</noautolink>

| *Page Link* | *Field One* | *Field Two* | *Field Three* | *Field Four* |
%SEARCH{
search="(lc(MyPageForm[name='FieldOne'].value) ~ lc('%URLPARAM{"search_field_one" encode="quote"}%') AND 
lc(MyPageForm[name='FieldTwo'].value) ~ lc('%URLPARAM{"search_field_two" encode="quote"}%'))"
type="query"
limit="150"
excludetopic="Web*" 
order="formfield(FieldOne),formfield(FieldTwo)"
nonoise="on"
format="| [[$topic]] | <i><b> $formfield(FieldOne)</b></i> | $formfield(FieldTwo) | $formfield(FieldThree) | $formfield(FieldFour) |"
}%

-- Contributors: ArthurClemens, StephenHallett - 09 Feb 2009



Comments & Questions about this Supplemental Document Topic

I would like to see a "most popular" list built with query search...

-- ArthurClemens - 06 Feb 2008

I am also very curious how to set up a web search that find topics that have web form F - and have one or multiple words in the topic text.

-- ArthurClemens - 15 Feb 2008

Thanks Arthur for initiating this cookbook page!

-- PeterThoeny - 02 Mar 2008

%SEARCH{type="query" "RequirementsForm[name='CompanySystem'].value='Intranet'"

what' the test for value is blank?

It is not %SEARCH{type="query" "RequirementsForm[name='CompanySystem'].value=''"

-- MartinCleaver - 29 Aug 2008

thank you StephenHallett for contributing "Pattern 3: Search named form fields using interactive user-input text ". I fixed the form field name in the search query, it needs to match the actual form field name.

-- PeterThoeny - 09 Feb 2009

Oops - yes thanks, and for complete correctness I edited the order and output format lines too. As a wider learning point, I have found the format: Myform[name='Fieldname with space'].value the best for referencing form field names which have spaces.

-- StephenHallett - 13 Feb 2009

Please use the Support forum if you have questions about TWiki features. This comment section is about the documentation of this topic.
Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r10 - 2009-02-13 - StephenHallett
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.