Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$startpos adjustment may return minus value. #297

Open
infinitail opened this issue Aug 31, 2023 · 1 comment
Open

$startpos adjustment may return minus value. #297

infinitail opened this issue Aug 31, 2023 · 1 comment

Comments

@infinitail
Copy link
Contributor

In extractRelevant() function $startpos variable is adjusted for keep text length. But some case like below, it may return minus value and bogus hilighted text.

$textlength = 323
$startpos = 95
$locations = 145
$rellength = 300

adjusted $startpos = 95 - (323 - 95) / 2 = -19

I suggest add max() for fix this issue.

        if ($textlength - $startpos < $rellength) {
            $startpos = $startpos - ($textlength - $startpos) / 2;
+           $startpos = max($startpos, 0);
        }
@nticaric
Copy link
Contributor

ok, please send a pull request

infinitail added a commit to infinitail/tntsearch that referenced this issue Sep 1, 2023
nticaric added a commit that referenced this issue Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants