[geeklog-cvs] geeklog: Ensure we get as many words as requested in the extract...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Thu Jun 11 16:23:02 EDT 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/a3617b9a512d
changeset: 7103:a3617b9a512d
user: Dirk Haun <dirk at haun-online.de>
date: Thu Jun 11 21:57:08 2009 +0200
description:
Ensure we get as many words as requested in the extracts for the search results
diffstat:
system/classes/search.class.php | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diffs (42 lines):
diff -r 536f78878a7a -r a3617b9a512d system/classes/search.class.php
--- a/system/classes/search.class.php Thu Jun 11 18:56:23 2009 +0200
+++ b/system/classes/search.class.php Thu Jun 11 21:57:08 2009 +0200
@@ -821,12 +821,20 @@
$start = 0 - $key;
$end = $num_words - 1;
$end = (($key + $m <= $word_count - 1) ? $key : $word_count - $m - 1);
+ $abs_length = abs($start) + abs($end) + 1;
+ if ($abs_length < $num_words) {
+ $end += ($num_words - $abs_length);
+ }
}
else
{
// Keyword in the middle of text
$start = 0 - $m;
$end = (($key + $m <= $word_count - 1) ? $m : $word_count - $key - 1);
+ $abs_length = abs($start) + abs($end) + 1;
+ if ($abs_length < $num_words) {
+ $start -= ($num_words - $abs_length);
+ }
$rt = '<b>...</b> ';
}
}
@@ -838,11 +846,14 @@
$end = $num_words - 1;
}
- for ($i = $start; $i <= $end; $i++)
+ for ($i = $start; $i <= $end; $i++) {
$rt .= $words[$key + $i] . ' ';
- $rt .= ' <b>...</b>';
+ }
+ if ($key + $i != $word_count) {
+ $rt .= ' <b>...</b>';
+ }
- return COM_highlightQuery( $rt, $keyword, 'b' );
+ return COM_highlightQuery($rt, $keyword, 'b');
}
/**
More information about the geeklog-cvs
mailing list