Excerpts

Summary: Shows fragment of page around given word(s).
Version: 20171110
Prerequisites: PmWiki2.2.56+
Status: beta
Maintainer: Petko (original author: MateuszCzaplinski)
Discussion: Excerpts-Talk

Questions answered by this recipe

Can I show (for example in my search results) a fragment of a page around given word, with the word shown in bold, as it's done in Google search results?

Description

After installation, two new markups are available:

Single excerpt

(:excerpt Group.Page "search terms" :) or
(:excerpt Group.Page term :)

This syntax displays one line, showing where in specified page is the "search terms" phrase, or "term" word.

Example:

 (:excerpt PmWiki.InitialSetupTasks "when you":)
- will find words around the first occurence of "when you" phrase in the PmWiki.InitialSetupTasks page, which will show as:

...n file (''local/config.php'') When you first install PmWiki, the ''l...

A pack of excerpts

(:excerpts Group.Page first_term second_term ... :)

The plural syntax (note the 's' in 'excerpts') allows to display several excerpts of the same page using one directive. It creates a single excerpt for each specified term.

Example:

 (:excerpts PmWiki.WikiGroup foo bar:)
- will find an excerpt for each of "foo" and "bar":

...e a default page in the group Foo, create a link to [=[[Foo/]]=...
....]]=]). To make a page called Bar in the group Foo, create a li...

Installation

Installation is standard: download excerpts.phpΔ, save it in your cookbook/ directory, add include_once("$FarmD/cookbook/excerpts.php"); to your local/config.php file.

Configuration parameters (optional):

$ExcerptSideWidth = 30;
How many characters of the page are included at each side of the matched fragment.

Notes

  • It's case insensitive as intended, but not for UTF-8 characters. I haven't yet came with a good solution; see source code for details. If you want to improve the code, please feel welcome. I'm also open for suggestions - please put them in comments, below.
  • Todo: The recipe should first try to match whole words, and match parts of the words only if that failed.
  • Todo: Test if the (:excerpts:) directive works properly both with single (') and double quotes ("). Then test Cookbook:SortByScore about the same (or doesn't the latter need to work with singles?).
  • Todo: The Markup() regexp should require whitespaces between (:excerpt or (:excerpts and characters written immediately afterwards.

Release Notes

  • 20171110 - Update for PHP 5.5 and 7.2, requires PmWiki 2.2.56 or newer (Petko)
  • 2007-09-30 - v1.2
    • removed unused ExcertpsToupper() function
    • added $ExcerptSideWidth
  • 2007-09-26 - v1.1 - bug fix, which helps to make Cookbook:SortByScore's lists cleaner when excerpts not required
  • 2006-12-21 - v0.9 - initial release, by MateuszCzaplinski

See Also

Contributors

Comments

See discussion at Excerpts-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.