incubator-answer
incubator-answer copied to clipboard
Highlighting Matched words in Search Results
Is your enhancement request related to a problem? Please describe
Current search results
I am not sure why particular line item is there in my search results.
related discussion: https://github.com/apache/incubator-answer/issues/798
Describe the solution you'd like
Highlight matched words of user input with color .text-danger.
- For question: Highlight keywords in title and summary.
- For answer: Highlight keywords in summary.
not sure if text-danger is the right choice
maybe background-color: var(--bs-highlight-bg)
is better?
but the backend doesn't give any info on the indices of word matches. So will this be purely a frontend change? maybe a small ts function that takes search words, excerpt text and question text and produces highlights.
what if the <SearchItem />
takes data: SearchResItem
and matches: SearchMatches
or maybe SearchMatches
is included into the SearchResItem
as optional field
SearchMatches
can be a simple type. something like
interface SearchMatches {
matches: Match[]
}
interface Match {
start: number;
end: number;
}
not sure if text-danger is the right choice maybe
background-color: var(--bs-highlight-bg)
is better?
Search engines like Google often change text colors, which may conflict with the browser's default page search colors if using a background color.
but the backend doesn't give any info on the indices of word matches. So will this be purely a frontend change? maybe a small ts function that takes search words, excerpt text and question text and produces highlights.
I think frontend matching is enough.
not sure if text-danger is the right choice maybe
background-color: var(--bs-highlight-bg)
is better?Search engines like Google often change text colors, which may conflict with the browser's default page search colors if using a background color.
but the backend doesn't give any info on the indices of word matches. So will this be purely a frontend change? maybe a small ts function that takes search words, excerpt text and question text and produces highlights.
I think frontend matching is enough.
@fenbox This enhancement might need more discussion. Currently the backend only returns the excerpt
([0:240]
chars at most) of a question or the answers.
If the first matched keyword appears in the middle of a very long text: How many words before the first matched keyword should be kept to make the search result context reasonable?
e.g.
... very loooooooooooong text. keyword whatever after it ...
not sure if text-danger is the right choice maybe
background-color: var(--bs-highlight-bg)
is better?Search engines like Google often change text colors, which may conflict with the browser's default page search colors if using a background color.
but the backend doesn't give any info on the indices of word matches. So will this be purely a frontend change? maybe a small ts function that takes search words, excerpt text and question text and produces highlights.
I think frontend matching is enough.
@fenbox This enhancement might need more discussion. Currently the backend only returns the
excerpt
([0:240]
chars at most) of a question or the answers.
- https://github.com/apache/incubator-answer/blob/dev/internal/repo/search_common/search_repo.go#L511
If the first matched keyword appears in the middle of a very long text: How many words before the first matched keyword should be kept to make the search result context reasonable?
e.g.
... very loooooooooooong text. keyword whatever after it ...
@kumfo He's right. You had clipped a portion of the content and returned. So, it's maybe need to make some adjustments here.
@Octobug
Hello, I have reviewed your description and first of all, the FetchExcept
method is a universal method that cannot be changed, You need add new method.
Then our consideration here is that when doing string truncation, if multiple keywords are submitted during the search, we will take the first keyword and 100 characters before and after it to truncate and display.
If you can solve it, you can submit a PR.
@Octobug
Hello, I have reviewed your description and first of all, the
FetchExcept
method is a universal method that cannot be changed, You need add new method.Then our consideration here is that when doing string truncation, if multiple keywords are submitted during the search, we will take the first keyword and 100 characters before and after it to truncate and display.
If you can solve it, you can submit a PR.
@kumfo Okay, thanks. I'll try to do it this weekend. If I fail I'll let you guys know. :D