Skip to content
Snippets Groups Projects
Commit fd687c18 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Merge pull request #545 from splitbrain/snippet_fixes

Snippet fixes
parents 90098477 43d58b76
No related branches found
No related tags found
No related merge requests found
...@@ -333,7 +333,7 @@ function ft_snippet($id,$highlight){ ...@@ -333,7 +333,7 @@ function ft_snippet($id,$highlight){
$pre = min($pre,100-$post); $pre = min($pre,100-$post);
} else if ($post>50) { } else if ($post>50) {
$post = min($post, 100-$pre); $post = min($post, 100-$pre);
} else { } else if ($offset == 0) {
// both are less than 50, means the context is the whole string // 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 // make it so and break out of this loop - there is no need for the
// complex snippet calculations // complex snippet calculations
...@@ -354,12 +354,12 @@ function ft_snippet($id,$highlight){ ...@@ -354,12 +354,12 @@ function ft_snippet($id,$highlight){
} }
// set $offset for next match attempt // set $offset for next match attempt
// substract strlen to avoid splitting a potential search success, // continue matching after the current match
// this is an approximation as the search pattern may match strings // if the current match is not the longest possible match starting at the current offset
// of varying length and it will fail if the context snippet // this prevents further matching of this snippet but for possible matches of length
// boundary breaks a matching string longer than the current match // smaller than match length + context (at least 50 characters) this match is part of the context
$utf8_offset = $utf8_idx + $post; $utf8_offset = $utf8_idx + $utf8_len;
$offset = $idx + strlen(utf8_substr($text,$utf8_idx,$post)); $offset = $idx + strlen(utf8_substr($text,$utf8_idx,$utf8_len));
$offset = utf8_correctIdx($text,$offset); $offset = utf8_correctIdx($text,$offset);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment