Tags:
search1Add my vote for this tag create new tag
, view all tags

Feature Proposal: New $count variable in format argument of formatted searches

Motivation

This was needed to implement a Blog system in pure wiki, but has many uses

Description

This allows to print the number of times a given regexp matches. Example:

%SEARCH{... format="... $count(.*?(---[+][+][+][+] ).*) comments"}%
Prints a count of comments in the page if each comment is a 4th level title

-- ColasNahaboo - 13 May 2005

Impact and Available Solutions

Documentation

To be added to the documentation of Search in FormattedSearch, after the row for $pattern:

$count(reg-exp) A regular expression pattern to count the number of times it appears in the text of a topic (does not search meta data). In case of a multiple="on" search, the pattern is applied to the line found in each search hit.
• Specify a RegularExpression that covers the whole text (topic or line), which typically starts with .*, and must end in .*
• Put text you want to count in parenthesis, like $pattern(.*?(from here.*?to here).*)
• Example: $count(.*?(---[+][+][+][+]) .*) counts the number of <H4> headers in a page
• This example has non-greedy .*? patterns to scan for the first occurrence of a header
• Limitation: Do not use .*) inside the pattern, e.g. $count(.*foo(.*)bar.*) does not work, but $count(.*foo(.*?)bar.*) does

Examples

see doc

Implementation

This feature could be made part of a more general mechanism, if ever designed. Maybe a search&replace variable?


Discussion:

How did I miss this? This really is a very useful feature. In considering how to implement FacetedNavigation, I realized this would be essential. I'd like to get this into DevelopBranch!

-- LynnwoodBrown - 24 Aug 2005

How do I count complete %SEARCH hits in the first place, that is only get the %NTOPICS w/o any other output? Useful when (blog) comments are in separate topics each.

-- MichaelDaum - 25 Aug 2005

Uh, got it:

%CALC{"$LISTSIZE(%SEARCH{"BlogComment" 
   web="Blog" scope="topic" 
   format="$topic" separator=", " nonoise="on"}%)"}%

-- MichaelDaum - 25 Aug 2005

But actually, I'd like to have a counter varialbe that enumerates the topics found, that is $hit is 1 for the first hit, 2 for the second and so on. Enumeration should take place AFTER ordering, obviously. Well, this is quite different to the proposal here (in-topic pattern counter). Should do a separate FeatureRequest ...

Hm, the hit counter could be done using css3 selectors but very few browsers implement that.

-- MichaelDaum - 25 Aug 2005

Lynnwood, you could also use the FormQueryPlugin's %MATCHCOUNT% variable that does just this.

(On top of that it's fast but that's off topic wink )

-- JosMaccabiani - 25 Aug 2005

Thanks Michael and Jos for the excellent solutions. Once again, I'm convinced that with enough work, you can get CALC to do just about anything. And FormQueryPlugin definitely seems like the way to go for implementing FacetedNavigation, given the number of simultaneous searches this requires.

Still, it seems to me that this feature is useful enough that adding a simple variable to search or formatted search would be worth exploring.

-- LynnwoodBrown - 25 Aug 2005

See also: CountingHeadings

-- ChristopherOezbek - 15 Sep 2005

I would like to propose that this topic be renamed to FormattedSearchRegexCountVariable since that would more accurately describe this feature as implemented. My motivation is to submit a feature request for a simple count variable for FormattedSearch - i.e. returns the number of hits from a search - which I believe the current name of this topic implies.

-- LynnwoodBrown - 23 Feb 2006

Renamed.

-- ArthurClemens - 23 Feb 2006

Thank-you Arthur! Now I can submit a FeatureRequest for a simple FormattedSearchCountVariable.

-- LynnwoodBrown - 23 Feb 2006

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpatch FormattedSearchCountVariableV1.patch r1 manage 1.5 K 2005-05-13 - 13:44 ColasNahaboo patch to implement this feature in cairo
Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r12 - 2006-02-23 - LynnwoodBrown
 
  • 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.