summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-02-15 16:01:09 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-02-15 16:01:09 +0100
commitfd687c182623383b66d845d9d010dfa905d3971d (patch)
tree825aafe3ff438e51056a2ea0617ef041b5d308f7
parent900984773e07ba34cbb6f6f7ed394210213153ec (diff)
parent43d58b76484489688582f407d73054a3d4ddcba1 (diff)
downloadrpg-fd687c182623383b66d845d9d010dfa905d3971d.tar.gz
rpg-fd687c182623383b66d845d9d010dfa905d3971d.tar.bz2
Merge pull request #545 from splitbrain/snippet_fixes
Snippet fixes
-rw-r--r--inc/fulltext.php14
1 files changed, 7 insertions, 7 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index bd8e6b866..87b5a7370 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -333,7 +333,7 @@ function ft_snippet($id,$highlight){
$pre = min($pre,100-$post);
} else if ($post>50) {
$post = min($post, 100-$pre);
- } else {
+ } else if ($offset == 0) {
// both are less than 50, means the context is the whole string
// make it so and break out of this loop - there is no need for the
// complex snippet calculations
@@ -354,12 +354,12 @@ function ft_snippet($id,$highlight){
}
// set $offset for next match attempt
- // substract strlen to avoid splitting a potential search success,
- // this is an approximation as the search pattern may match strings
- // of varying length and it will fail if the context snippet
- // boundary breaks a matching string longer than the current match
- $utf8_offset = $utf8_idx + $post;
- $offset = $idx + strlen(utf8_substr($text,$utf8_idx,$post));
+ // continue matching after the current match
+ // if the current match is not the longest possible match starting at the current offset
+ // this prevents further matching of this snippet but for possible matches of length
+ // smaller than match length + context (at least 50 characters) this match is part of the context
+ $utf8_offset = $utf8_idx + $utf8_len;
+ $offset = $idx + strlen(utf8_substr($text,$utf8_idx,$utf8_len));
$offset = utf8_correctIdx($text,$offset);
}