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.

Position of the matched text in an Index

See original GitHub issue

Is there an option to retrieve the position of the searched text in a given string that flexsearch matches? would be super useful to generate a preview of the content.

Let us say there are two strings in the index 1: Lorem Ipsum is simply dummy text of the printing and typesetting industry. 2. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.

If I search using flexsearch for query printing it will return string 1.

now, with the returned index id, I also want to show a preview (+ or - 4 words from the matched text) - example: text of the printing and typesetting industry. Is there a way to do this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
haikyuucommented, Jun 19, 2021

First of all, thanks for this amazing library. That’s some great engineering work.

This is actually not supported. It could be provided by a future plugin. Also you can try to solve this manually. After getting back the result from indexed documents you need to find the first occurrence of the given query.

That defeats the point of the library. If I had to implement the exact algorithm used to perform search, I wouldn’t use the library in the first place.

A good enough solution is to return just the index of the (first letter of the) occurrence in the string.

a future plugin

Is there an API for adding plugins? any examples?

1reaction
bobvanderlindencommented, Nov 15, 2022

I’m currently doing a regex lookup on the resulting documents for words in the query. First split the query by to get the words in the query. Create a regex that includes all of these words, by joining them using |. Then find all matches in the found document. Using those matches and their index and length I can highlight those findings. It doesn’t support fuzzy matching.

One implementation can be found here: https://github.com/verwijsafspraken/verwijsafspraken/blob/5fe4da30f8dbac922c8da44b4eff712a9d2e6971/src/search.js#L86

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Find Position of a Regex Match - PYnative
These Match object methods are used to access the index positions of the matching string. ... Search the pattern using the search() method....
Read more >
Return positions of a regex match() in Javascript?
When dealing with a non-global regex (i.e., no g flag on your regex), the value returned by .match() has an index property...all you...
Read more >
Position of first partial match - Excel formula - Exceljet
The MATCH function returns the position or "index" of the first match based on a lookup value in a range. MATCH supports wildcard...
Read more >
How to Find the Position Index of a Regex Match Result in ...
We can find the indexes of one or more matches of a regex pattern within a JavaScript string by using the RegExp.prototype.exec method....
Read more >
INDEX & MATCH Functions Combo in Excel (10 Easy ...
But if you have multiple instances of matching (for example Apple Inc and Apple Corporation, then the MATCH function would return the position...
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