Position of the matched text in an Index
See original GitHub issueIs 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:
- Created 4 years ago
- Reactions:11
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First of all, thanks for this amazing library. That’s some great engineering work.
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.
Is there an API for adding plugins? any examples?
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