Tags:
create new tag
, view all tags

Question

I find the output of a Google search quite useful because it displays some context around the search hits and highlights the terms, giving you a hint as to whether it's worth drilling down into the page.

Is there a way to create this kind of output with off the shelf TWiki, or if not, does anyone have any design suggestions on how this kind of support can/should be added to TWiki (I would be interested in doing this).

I've done some tinkering, and have hacked together something to do just this. The following is the section of code from Search.pm I've modified. It's not pretty but it does what I need it to within the time constraints of the task I'm really working on.

    } 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;

        # My new code begins here.  This basically supports a special
        # $parahits variable that can be used within a format= in a 
        # SEARCH
        #
        # $parahits will contain an HTML bulleted list of 'paragraphs'
        # that contain the search term. The matching terms are rendered
        # in bold.
        # 
        # TWiki::makeTopicSummary was modified to accept an additional
        # numeric parameter -- the max number of characters in the topic
        # summary. -1 means no max.
        #
        my @lines = split("\n", $text);
        my $parahits = "<ul>";
        foreach my $line (@lines) {
           if ($line =~ /$theSearchVal/) {
               $parahits .= "<li>" . &TWiki::makeTopicSummary( $line, $topic, $thisWebName, -1 );
           };
        };
        $parahits .= "</ul>";
        $parahits =~ s/($theSearchVal)/\<b\>$1\<\/b\>/g;
        $tempVal =~ s/\$parahits/$parahits/geos;

  • TWiki version: 1 Dec 2001
  • Web server:
  • Server OS:
  • Web browser:
  • Client OS:

-- FrankSmith - 03 Jan 2002

Answer

I don't know if you still want it, or if this solution pleases you, but you can check PhotonSkin and PhotonTWikiMods.

-- EstebanManchado - 28 May 2003

I was not able to grok it quickly, Esteban - does your mod select only words NEAR keywords instead of full BookView? If yes, one more point for you to get your mod included into core. This was one of the points Frank asked for, IIUC.

-- PeterMasiar - 28 May 2003

Sorry for replying so late, I just saw your message :-(. Yes, the idea is searching for one of the terms in the body text, take some context, and highlight every search term in that context. So, the result is something like what is already shown in regular TWiki searches, but not necessarily the beginning of the topic, and with search terms highlighted.

If you like Google-like colors, you can also install PhotonTWikiMods and have it highlight every search term a la Google-cache once you click in a search result :-) (see the left screenshot in PhotonTWikiMods).

And, now you mention BookView, PhotonSearch now has a BookView mode (see the documentation in PhotonSkin).

-- EstebanManchado - 26 Jun 2003

Topic revision: r7 - 2004-01-02 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.