Controlling excerpt length
This help file describes advanced techniques for customizing the "Show Examples" feature. That feature is described at: How to show examples of keyword matches in the search result listings.
By default, each example will contain up to 36 characters of text before and after the keyword. The system will display as much text as possible, but will split the examples at word boundaries, and less text will be shown if the keyword appears at the very beginning or end of the file.
Common customizations are:
-
To customize the amount of text before and after the keyword, edit the library file "search/searchmods/common.pl" and find the line like this:
my $chars_per_context_hit = 36;Simply replace 36 with the desired number of characters. The minimum allowed value is 1.
-
To customize the amount of text around the keyword, and to have unequal amounts of text before and after, edit the same library file and find the code that looks like this:
([^\=]{0,$chars_per_context_hit})($str_pattern)([^\=]{0,$chars_per_context_hit})(Note that this code appears in two places in the library file, and you will need to edit both occurrences if you customize it. The code above appears as a substring within a longer line of code.)
This is the pattern match which extracts the text before the keyword, then the keyword, and then the text after the keyword. The number "0" and the variable
$chars_per_context_hitare entered within curly braces to describe a range of characters to match. Within the pattern, there are two ranges: the first describes the text before the keyword, and the second describes the text after the keyword.To match 100 characters before the keyword, and 50 characters after, replace the above code with:
([^\=]{0,100})($str_pattern)([^\=]{0,50})To match 5 characters before, and 300 characters after, use:
([^\=]{0,5})($str_pattern)([^\=]{0,300})Note that your second number in the
{0,x}set must be at least 1. The 1 minimum will always match on the automatic whitespace boundary that comes before and after the keyword, and so a range of{0,1}will mean "zero length", but that second number must be 1 or greater in order for the system to work.
With these code customizations, the changes will take effect immediately. There is no need to rebuild the index files.
"Controlling excerpt length"
http://www.xav.com/scripts/search/help/1158.html