Tags:
create new tag
view all tags

Feature Proposal: Query Syntax in SEARCH Format

Motivation

Ability to use query syntax to format meta data, such as attachments.

Description and Documentation

TWiki already has a QuerySearch for VarSEARCH of type="query" and for VarIF (IfStatements). Being able to use the same query language to format the output is a logical enhancement.

The FormattedSearch has variables to render meta data, such as $formfield(), $rev(), $parent(). A new $query() variable is proposed to format any meta data available in the QuerySearch.

Examples

1. Access file comments:

Assuming the current page has a file attachment called mugshot.jpg. It is possible to get the file comment of with the following query:

%SEARCH{ "form.name='UserForm'" type="query" nonoise="on" format="   * $topic: $query(attachments[name='mugshot.jpg'].comment)" }%

This returns a bullet list with topic name and file comment of mugshot.jpg (if any).

2. Access file size:

Return the size of all .gif files attached to the current page:

%SEARCH{ "%TOPIC%" scope="topic" nonoise="on" format="$query(attachments[name~'*.gif'].size)" }%

This returns an array of file sizes, such as [625, 158] if multiple .gif files are attached, or an integer if a single file is attached.

Impact

Implementation

-- Contributors: PeterThoeny - 2010-02-09

Discussion

Outstanding issue: The query syntax supports parenthesis. The format="..." syntax for variables is $variable(...). There is an ambiguity if the query contains parenthesis, such as $query(attachments[name ~ '*.png' AND date > d2n('2010-01-01').arraysize])=. How to solve that? Options:

1. Do nothing for initial implementation, e.g. live with limitation that parenthesis cannot be used inside a $query() variable.

2. Parse properly, e.g. keep track of number of opening and closing parenthesis. This is expensive at runtime.

3. Require to escape parenthesis inside $query(), such as $query(attachments[name ~ '*.png' AND date >= d2n\('2010-01-01'\).arraysize])

4. Introduce an end token, such as $query(...#end). This is easy to implement, but is not so intuitive and looks ugly.

I favor number 1 or 3. Opinions?

-- PeterThoeny - 2010-02-09

Looks good proposal - i support this.

-- SopanShewale - 2010-02-10

I checked in the initial code and doc. For now it is 1 (do not support parenthesis in query). Doc is at http://develop.twiki.org/~twiki4/cgi-bin/view/TWiki/FormattedSearch - see $query(query-syntax)

-- PeterThoeny - 2010-02-16

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2010-03-21 - PeterThoeny
 
  • 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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.