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?
After installation, two new markups are available:
(:excerpt Group.Page "search terms" :) or
(:excerpt Group.Page term :)
(:excerpt PmWiki.InitialSetupTasks "when you":)
...n file (''local/config.php'') When you first install PmWiki, the ''l...
A pack of excerpts
(:excerpts Group.Page first_term second_term ... :)
(:excerpts PmWiki.WikiGroup foo 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 is standard: download excerpts.phpΔ, save it in your
cookbook/ directory, add
include_once(" to your
Configuration parameters (optional):
$ExcerptSideWidth = 30;
- How many characters of the page are included at each side of the matched fragment.
- 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
(:excerptsand characters written immediately afterwards.
- 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
- Petko, current maintainer
- MateuszCzaplinski, original author
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.