incubator-answer icon indicating copy to clipboard operation
incubator-answer copied to clipboard

Highlighting Matched words in Search Results

Open surapuramakhil opened this issue 1 year ago • 7 comments

Is your enhancement request related to a problem? Please describe

Current search results 307235898-1b4ba40b-566b-413b-8992-79d49e7b7b24

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.

surapuramakhil avatar Feb 26 '24 12:02 surapuramakhil

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.

zahash avatar Feb 27 '24 11:02 zahash

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;
}

zahash avatar Feb 27 '24 12:02 zahash

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 avatar Mar 04 '24 03:03 fenbox

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 ...

Octobug avatar Mar 15 '24 08:03 Octobug

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.

LinkinStars avatar Mar 15 '24 08:03 LinkinStars

@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 avatar Mar 15 '24 09:03 kumfo

@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

Octobug avatar Mar 15 '24 09:03 Octobug