question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlight terms in search results

See original GitHub issue

Feature Suggestion

In the search result page, highlight the user’s search keywords in the result text.

Possible Implementation

Backend: The interface for search results for the various backends should be changed to return optionally an array of highlight positions:

type Position = {
  term: string; // the actually matched word(s) after stemming etc
  field: JSONPath; // where in the doc was it found, eg title or body
  pos: number; // index in string of first character
}

These would be forwarded to the client in GET /search/query responses.

Obviously support for this is variable - Lunr has it (demo), ElasticSearch also IIRC. But I can’t find any evidence that Postgres does.

Client: I think I built something like this once, or maybe I just spent a lot of time fixing off by one bugs in something that was already there - those memories are well repressed 😅 But essentially you’re going to walk through each matchable field, building up an array of text fragments and <span>s or whatever, and then rendering that in your component. Of course there are edge cases around complex unicode characters and so on.

Context

Now we have search in TechDocs, it’s a much more useful feature for us. However, that in turn builds up demand for common UX affordances like this. Highlighting results is very common in search pages, from Google on down.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
kuangpcommented, Mar 4, 2022

still interested

2reactions
kuangpcommented, Nov 1, 2021

still very interested in this

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to highlight search terms in your search results - Medium
Looking for the word you searched for in the search results? It'd be easier if the search terms were highlighted. Did you spot...
Read more >
How to highlight search results - Manticore Search
You can highlight keywords in text in Manticore Search using several methods. ... CALL SNIPPETS('my text with keyword', 'index', 'keyword');.
Read more >
How to quickly highlight recurring text in Word | TechRepublic
How to highlight in Word using Find · Click Find in the Editing group or press Ctrl+F to open the Navigation pane. ·...
Read more >
Highlight Search Terms in Results — MongoDB Atlas
The Atlas Search highlight option adds fields to the result set that display search terms in their original context. You can use it...
Read more >
Here's What Google's New Highlight Feature Means for Your ...
For several years, Google has tested highlighting content on webpages based on the featured snippet you click on in Google search results. It ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found