Commit 86c7e1133ce6edf4841cc402c828260779ed0011
1 parent
f4c63877
KTS-673
"The search algorithm needs some work" Updated. Fixed an issue with the simple highlighting. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7242 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
28 additions
and
20 deletions
search2/search/expr.inc.php
| @@ -856,38 +856,46 @@ class TextQueryBuilder implements QueryBuilder | @@ -856,38 +856,46 @@ class TextQueryBuilder implements QueryBuilder | ||
| 856 | { | 856 | { |
| 857 | $offset=stripos($this->text, $word); | 857 | $offset=stripos($this->text, $word); |
| 858 | 858 | ||
| 859 | - if ($offset == false) | 859 | + if ($offset === false) |
| 860 | { | 860 | { |
| 861 | return array(false, false); | 861 | return array(false, false); |
| 862 | } | 862 | } |
| 863 | 863 | ||
| 864 | - $text = substr($this->text, 0 , $offset); | ||
| 865 | - | ||
| 866 | - $lastsentence = strrpos($text, '.'); | ||
| 867 | - if (!$lastsentence) $lastsentence=0; | ||
| 868 | - | ||
| 869 | - if ($offset - $lastsentence > $maxlen) | 864 | + if ($offset == 0) |
| 870 | { | 865 | { |
| 871 | - $lastsentence = $offset - $maxlen; | 866 | + $startOffset = 0; |
| 872 | } | 867 | } |
| 868 | + else | ||
| 869 | + { | ||
| 870 | + $text = substr($this->text, 0 , $offset); | ||
| 873 | 871 | ||
| 874 | - $text = substr($this->text, $lastsentence, $offset - $lastsentence); | 872 | + $lastsentence = strrpos($text, '.'); |
| 873 | + if ($lastsentence === false) $lastsentence=0; | ||
| 875 | 874 | ||
| 876 | - $wordoffset= strlen($text)-1; | ||
| 877 | - $words = $maxwords; | ||
| 878 | - while ($words > 0) | ||
| 879 | - { | ||
| 880 | - $text = substr($text, 0, $wordoffset); | ||
| 881 | - $foundoffset = strrpos($text, ' '); | ||
| 882 | - if ($foundoffset === false) | 875 | + if ($offset - $lastsentence > $maxlen) |
| 883 | { | 876 | { |
| 884 | - break; | 877 | + $lastsentence = $offset - $maxlen; |
| 885 | } | 878 | } |
| 886 | - $wordoffset = $foundoffset; | ||
| 887 | - $words--; | 879 | + |
| 880 | + $text = substr($this->text, $lastsentence, $offset - $lastsentence); | ||
| 881 | + | ||
| 882 | + $wordoffset= strlen($text)-1; | ||
| 883 | + $words = $maxwords; | ||
| 884 | + while ($words > 0) | ||
| 885 | + { | ||
| 886 | + $text = substr($text, 0, $wordoffset); | ||
| 887 | + $foundoffset = strrpos($text, ' '); | ||
| 888 | + if ($foundoffset === false) | ||
| 889 | + { | ||
| 890 | + break; | ||
| 891 | + } | ||
| 892 | + $wordoffset = $foundoffset; | ||
| 893 | + $words--; | ||
| 894 | + } | ||
| 895 | + $startOffset = $lastsentence + $wordoffset; | ||
| 888 | } | 896 | } |
| 889 | 897 | ||
| 890 | - $startOffset = $lastsentence + $wordoffset; | 898 | + |
| 891 | 899 | ||
| 892 | $nextsentence = strpos($this->text, '.', $offset); | 900 | $nextsentence = strpos($this->text, '.', $offset); |
| 893 | 901 |