Tags:
create new tag
, view all tags
New feature: FormattedSearch can be nested. For example, you want to search for some topics, then form a new search for each topic found in the first search. The idea is to build the nested search string using a formatted search in the first search.

This is an advanced feature that not everyone needs, but it has no performance impact, is hidden enough (not in the way), and allows one to build powerful queries. We needed this functionality at work for a dashboard application that pulls data out of topics that are arranged in a hierarchy based on TWikiForms.

Here is an example. Let's search for all topics that contain the word "culture" (first search), and let's find out where each topic found is linked from (second search).

  • First search:
    • %SEARCH{ "culture" format="   * $topic is referenced by: (list all references)" nosearch="on" nototal="on" }%
  • Second search. For each hit we want this search:
    • %SEARCH{ "(topic found in first search)" format="   $topic" nosearch="on" nototal="on" }%
  • Now let's nest the two. We need to escape the second search, e.g. the first search will build a valid second search string. Note that we escape the second search so that it does not get evaluated prematurely by the first search:
    • Use $percnt to escape the leading percent of the second search
    • Use \" to escape the double quotes
    • Use $dollar to escape the $ of $topic
    • Use $nop to escape the }% sequence

Write this:

%SEARCH{ "culture" format="   * $topic is referenced by:$n      * $percntSEARCH{ \"$topic\" format=\"   $dollartopic\" nosearch=\"on\" nototal=\"on\" }$nop%" nosearch="on" nototal="on" }%

To get this:

Disabled because the topic was timing out

% SEARCH{ "culture" format=" * $topic is referenced by:$n * $percntSEARCH{ \"$topic\" format=\" $dollartopic\" nosearch=\"on\" nototal=\"on\" }$nop%" nosearch="on" nototal="on" }%

Changes are in TWikiAlphaRelease:

  • New parameters introduced for format="..." FormattedSearch:
    $nop or $nop() Is a "no operation". This variable gets removed; useful for nested search
    $quot Double quote ("). Alternatively write \" to escape it
    $percnt Percent sign (%)
    $dollar Dollar sign ($)

  • %SEARCH{}% is evaluated twice in TWiki.pm

Doc in FormattedSearch is updated but might need some work.

-- PeterThoeny - 17 May 2002

Thanks, a wonderful feature! Can be used for a lot more than described -- basicly an "and".

-- RandyKramer - 17 May 2002

For simple AND search it is easier to use the SearchWithAnd feature

-- PeterThoeny - 17 May 2002

This looks very powerful and very useful. However, it would be easier to use if the same '\' character was used to escape everything rather than requiring $dollar and so on.

-- RichardDonkin - 18 May 2002

this is excellent, thanks! i checked out the cvs tree and started using it this evening. some of my search statements are now upwards of 6 lines long, largely due to this :^)

-- SteveMokris - 06 Jun 2002

We have web with IT related topics translated to several languages. Structure of topic page: SomeTopic

  • connotation 1
    • example blah
    • translations
      • 1st
      • 2nd
  • connotation 2
    • example blahblah
    • translations
      • first
      • second

Is there any possibility to get this:

topic connotation translation1 translation2 example
SomeTopic 1 1st 2nd blah
2 first second blahblah

number of translations is given (invariable) =%SEARCH{ "..." multiple="on" regex="on" nosearch="on" format="| $topic | $pattern(.*?connotation(...)....*) | ... |" }% I know how to construct regexp but I don't know how to parse topic page .. (must I use XML tags or something like that)

-- DavidVana - 07 Feb 2005

Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r10 - 2005-02-15 - SamHasler
 
  • 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-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.