olivernn/lunr.js — pull request #58 by gjtorikian (2013-12-03 02:43:51+00:00)
Title: Provide context

This is a start to resolving #25.

Right now it seems to be pretty easy to find the original position of a matching token, as I've done here. What I'm having a hard time doing is getting the original, untokenized document back. It seems to be impossible currently. I'm very new to the code, though, and I maybe be overlooking something.

What I'd like to do is this:

Given a text of: `Professor Plumb has a green plant in his study`

And a search of: `green plant`

I want to get the index of the matched token (in this case, `24`).

From there, I'd like to devise some sort of extraction, so that the result returned to the user is actually something like a summary: `...has a green plant in his...`. This way, the reader can kind of get a "preview" of what the search yielded in the doc. (This is probably best handled outside the core code.)