Searching with quoted term doesn't highlight the whole term

AI-generated summary

Users report that searching with a quoted term (e.g., “ost.io”) doesn’t highlight the entire phrase as expected — only arbitrary words are highlighted, and sometimes quotes appear in the results gerhard. zogstrip notes that quotes aren’t needed for exact matches, but the issue persists. riking suggests the highlighter should strip quotes, though gerhard observes that this leads to double quotes appearing in results. sam confirms the fix is involved — the current highlighter only handles individual words, not full terms. codinghorror emphasizes the urgency, calling the UI behavior “disastrous” and questioning whether quoted phrases are even being searched correctly. sam later announces the fix is complete, centralizing highlighting logic and ensuring exact term matching via this commit. However, sam notes an edge case: italicized words (e.g., really) break the algorithm because it matches raw text indexes — a fix would require matching against a normalized text version of the post.

Continuing the discussion from The term "ost.io" creates trouble for search:

I’d expect it to highlight the whole term, but it highlights just arbitrary words.

2 Likes

You don’t need the quotes for an exact term match :wink:


If this is an easy fix we should fix it @sam

2 Likes

Looks to me like the highlighter just needs to strip out the quotes.

It’s still not highlighting the quoted term and now it shows double quotes for the search term.

3 Likes

I want to get to fixing this but its a fairly involved fixed, the highlighter needs to understand this behavior, it only highlights words now not full terms.

I really, really want this fixed, it is pretty disastrous from a UI perspective, also I’m not even sure it’s searching for a full quoted phrase in this scenario?

Done per:

per:

https://github.com/discourse/discourse/commit/0791d740a634a70cb8ffb7f762f1a31353560209

I changed it so we only match whole words, centralized the highlighting code and deal with exact terms.

6 Likes

One interesting edge case here is that the really being in italics in your post breaks the algorithm.

Cause we match the index and then try to match raw, we are going to have to change it to try to do the exact match on a normalized text only version of the post.

3 Likes