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

Cutting first and last word of summary while highlighting query tokens in summary text. #93

Open
awroblewski opened this issue Oct 16, 2020 · 0 comments

Comments

@awroblewski
Copy link

awroblewski commented Oct 16, 2020

Q A
Bug report? yes

Hello,

I got a problem while the Helper at location src/LuceneSearchBundle/Helper/HighlighterHelper.php:getHighlightedSummary($text, $queryTokens) which tries to highlight the query token in a given summary text.

Please focus line 102 - 110

            $tokens = explode(' ', $summary);

            if (strtolower($tokens[0]) != strtolower($tokenInUse)) {
                $tokens = array_slice($tokens, 1, -1);
            } else {
                $tokens = array_slice($tokens, 0, -1);
            }

            $trimmedSummary = implode(' ', $tokens);

The summary is tokenized into an array with separator ' ', means we have an array of all words separated by ' '. In the subsequent line 104 the if-clause checks whether the first entry of the tokenized summary array is not identical to the query token which in my case is almost always true. In this case array_slice in line 105 will cut the first and last entry of the tokenized summary array as the offset parameter is 1 and the lenght parameter is set to -1. Line 110 glues everything back together using separator ' '.

Example:
If I fed the method with
$text = "The quick brown fox jumps over the lazy dog"
$queryTokens = ["Fox"]

which resolves at line 102 to
"The quick brown fox jumps over the lazy dog" as $summary and "Fox" as $tokenInUse.

The method returns
"quick brown <span class="highlight">fox</span> jumps over the lazy

missing the first word and last word.

Can anyone please advice whether this is a bug or whether maybe I miss something?

Many thanks!

@awroblewski awroblewski changed the title Cutting first word of summary while highlighting query tokens in sunnary text. Cutting first word of summary while highlighting query tokens in summary text. Oct 16, 2020
@awroblewski awroblewski changed the title Cutting first word of summary while highlighting query tokens in summary text. Cutting first and last word of summary while highlighting query tokens in summary text. Oct 16, 2020
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

1 participant