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":)
A pack of excerpts
(:excerpts Group.Page first_term second_term ... :)
(:excerpts PmWiki.WikiGroup foo bar:)
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.
- 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 discussion at Excerpts-Talk