Tags:
create new tag
view all tags

Question

I'd like to put a portion of the search results into a variable and use that variable elsewhere. Better yet, I would like to use the result portion in a view template. Simply put, the following search tells me how many registered users I have:

%SEARCH{ "[N]ame:;Email:;Location:" web="Main" type="regex" nosummary="on" nosearch="on" format="$nop"}%

which results in something like: "Number of topics: 780"

I am not a regex guru - I was hoping someone could point me to a solution -- using the value in a VIEW template is my ultimate goal.

Thanks

Environment

TWiki version: TWikiRelease04Sep2004
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Solaris 9
Web server: Apache
Perl version: 5.8.7
Client OS: Winxp
Web Browser: FireFox 1.5.1
Categories: Search

-- SteveRJones - 27 Feb 2006

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

If you just want to calculate the total, use a spreadsheet formula to increase a counter on each hit, then read the counter elsewhere.

Example:

%CALC{$SET(total,0)}%
%SEARCH{ "testing" type="regex" nosearch="on" nototal="on" format="$percntCALC{$SETM(total,+1)}$percnt" }%
The total is: %CALC{$GET(total)}%

Output:

The total is: 320

You can do more fancy stuff, such as conditionals based on a $pattern() in the FormattedSearch.

-- PeterThoeny - 27 Feb 2006

Ack, I never thought of that! But $pattern and regex's still have me stymied. Peter, I learn by typically testing and watching how code iteratively operates - but using $pattern is typically an all or nothing - it either works or it doesn't and all my attempts seem to not work. Any pointers to some really good tutorials on making regex' work?

Thanks

-- SteveRJones - 28 Feb 2006

It takes some time to get used to regular expressions. TWiki's doc is at RegularExpression. I learned a lot from the Perl Camel book, ISBN:0-596-00027-8

Check out also:

-- PeterThoeny - 28 Feb 2006

Ok, I just purchased used books from Amazon - Perl book and master Regular Expressions. I'm determined!

Thanks Peter!

-- SteveRJones - 28 Feb 2006

smile Remembers me to have a look into my copy of Mastering Regular Expressions once in a while. Did get this as christmas present two years ago.

-- FranzJosefSilli - 28 Feb 2006

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2006-02-28 - FranzJosefSilli
 
  • 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.