Tags:
create new tag
, view all tags

Implemented: Formatted Search with $formname variable

Using a FormattedSearch you can already retrieve the value of form fields using $formfield(). With the new $formname variable you can get the name of the form attached to a topic.

Contributors:
-- FrankSmith - 05 Oct 2002
-- PeterThoeny - 15 Feb 2004

Here's the code I put into Search.pm to implement this.

With this minor enhancement, I was able to implement a Slashdot style site using a few lines of TWiki code. Check it out at http://emdebian.sourceforge.net/cgi-bin/twiki/view/Main/AtAGlance

Be aware that it's a work in progress...


#=========================
sub getMetaFormName
{
    my( $theMeta ) = @_;

    my %form = $theMeta->findOne( "FORM" );
    if ( %form ) {
        my $formName = $form{"name"};
        return $formName;
    } else {
        return "";
    };

}

.....

           } elsif( $theFormat ) {
                # free format, added PTh 10 Oct 2001
                if( ! $text ) {
                    ( $meta, $text ) = &TWiki::Store::readTopic( $thisWebName, $topic );
                }
                $tempVal =~ s/\$summary/&TWiki::makeTopicSummary( $text, $topic, $thisWebName )/geos;
                $tempVal =~ s/\$formfield\(["']?\s*([^\)'"]*)\s*['"]?\)/getMetaFormField( $meta, $1 )/geos;
                $tempVal =~ s/\$pattern\(\s*(.*?\s*\.\*)\)/getTextPattern( $text, $1 )/geos;
                $tempVal =~ s/\$formname/getMetaFormName( $meta )/geos;

                my @lines = split("\n", $text);
                my $parahits = "<ul>";
                foreach my $line (@lines) {
                   my $ts = &TWiki::makeTopicSummary( $line, $topic, $thisWebName, -1 );
                   $ts =~ s/($theSearchVal)/\<b\>$1\<\/b\>/g;
                   if ($line =~ /$theSearchVal/) {
                       $parahits .= "<li>" . "*" . $topicFormField{$topic}. ":* " . $ts . " " . $topic . " ";
                   };
                };

-- FrankSmith - 05 Oct 2002

This enhancement is now in TWikiAlphaRelease. Thanks Frank!

Index: Search.pm
===================================================================
RCS file: /cvsroot/twiki/twiki/lib/TWiki/Search.pm,v
retrieving revision 1.67
diff -c -r1.67 Search.pm
*** Search.pm   9 Feb 2004 05:02:15 -0000       1.67
--- Search.pm   15 Feb 2004 21:03:21 -0000
***************
*** 877,882 ****
--- 877,883 ----
                  }
                  $tempVal =~ s/\$summary/&TWiki::makeTopicSummary( $text, $topic, $thisWebName )/geos;
                  $tempVal =~ s/\$formfield\(\s*([^\)]*)\s*\)/getMetaFormField( $meta, $1 )/geos;
+                 $tempVal =~ s/\$formname/_getMetaFormName( $meta )/geos;
                  $tempVal =~ s/\$pattern\(\s*(.*?\s*\.\*)\)/getTextPattern( $text, $1 )/geos;
                  $tempVal =~ s/\$nop(\(\))?//gos;      # remove filler, useful for nested search
                  $tempVal =~ s/\$quot(\(\))?/\"/gos;   # expand double quote
***************
*** 1025,1030 ****
--- 1026,1051 ----
  #=========================
  =pod

+ ---++ sub _getMetaFormName (  $theMeta )
+
+ Returns the name of the form attached to the topic
+
+ =cut
+
+ sub _getMetaFormName
+ {
+     my( $theMeta ) = @_;
+
+     my %aForm = $theMeta->findOne( "FORM" );
+     if( %aForm ) {
+         return $aForm{"name"};
+     }
+     return "";
+ }
+
+ #=========================
+ =pod
+
  ---++ sub getTextPattern (  $theText, $thePattern  )

  Not yet documented.

-- PeterThoeny - 15 Feb 2004

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2004-02-15 - 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-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.