-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
highlight search keywords #97
Comments
There are a couple of issues requesting this feature. It involves quite a few changes to the way lunr works. I made a start on an implementation here but I haven't got round to completing it. I'll try and spend some more time with it this week and see if I can get something out for people to try. |
Is this issue already solved? I didn't find the way to do that with lunrjs... |
Sorry, still don't have a decent answer to this. It involves quite a lot of change to lunr and I'm not entirely convinced with the current implementation I put together (linked in the comment). I need to spend some more time thinking about how best to implement highlighting without sacrificing either index size or performance, and that takes some time! |
If it helps anyone I achieved this functionality by using BlastJS http://julian.com/research/blast/ |
@olivernn I understand you were trying to get the right balance between index size and performance. Will it be possible for you to describe what approach were you trying/planning in branch |
@olivernn Is it possible to get to know which stem word actually matched? If yes, then I can easily use that information with the BlastJS library mentioned above by @hudakdidit |
What I was trying to do was to wrap the token in a It involved vast changes to the existing way lunr works, and in the end I think I decided that rather than try and retrofit this kind of feature into the existing architecture a bigger rethink was required. The problem with that is getting the time to really work through what a different architecture would look like, time I just haven't had :( As for getting the step that matched, you would basically have to re-implement parts of what the
There is no easier or more efficient way of doing this with the current set up of the lunr. |
I would like to realize this with a highlighting component. However, first of we need to make sure that highlighted words and matches by lunr are exactly the same for a good usability concept. Therefore I created #200. |
@julmot
Seemed "good enough" to me. I could have also used the full Lunr pipeline to get the stemmed words, but then the highlights would look weird (e.g. you search for 'Persistence' and it highlights 'persist') |
@drallgood Thanks for letting me know. I don't think it would be weird, rather it would be consistent. Imagine a situation where a user searches for "Searched". Lunr will find files containing "searching". But a highlighting component will highlight nothing (different than expected), as there is not the exact term "searched" inside. Do you know a way to get all found words, also "searching" in this example? |
This looks like a duplicate of #25 |
@d0ugal There are a couple of issues that are similar here |
@olivernn I'm not sure that I understood your comment correctly, so maybe the following is the same thing your said: I think the Lucene way of highligting terms
I have no deep experience with lunr so far, but it seems to be that this approach would not require large refactorings of the code. Or I may be completely mistaken. |
Hello @drallgood , |
@hajarghaem The basic idea is as follows:
Some code (this is actually embedded in an jQuery autocomplete definition):
Probably not the nicest code, but it works ;) |
The latest version of Lunr does provide support for highlighting matches in documents. There is a demo showing this in action. To be clear, Lunr does not provide the actual highlighting, but it is now able to return the positions of keywords that did match. This should enable the use of other libraries to perform the highlighting of terms in a page. Please try it out and let me know any feedback. |
I can't seem to get the position of the terms returned from the result in the metaData attribute. How can I get the position? |
@clanofnoobs please open a new issue showing what you've tried and I'll take a look. I'm closing this issue now as there is support for highlighting terms with lunr. If there are problems with getting highlighting to work they should considered bugs and a new issue should be opened. |
For anyone who comes across this, in reference to @clanofnoobs's question, the this.metadataWhitelist = ['position'] From the bottom of https://lunrjs.com/guides/core_concepts.html |
what is "request.term" within tokenizer |
I have a requirement that search keywords should be highlighted in the found documents, is there a way to do this with lunrjs atm ?
The text was updated successfully, but these errors were encountered: