c# - Lucene.net - How do I extract small snippets of texts from each match? -


http://quranx.com/search?q=oh+people+of+heaven&context=quran

could tell me how change following code show snippets of text each match result? i've tried reading through examples etc can find relevant information newer version of lucene java. lucene seems of black box of magic me.

public static ienumerable<searchresult> search(     string querystring,      out int totalresults,     int maxresults = 100) {     totalresults = 0;     if (string.isnullorempty(querystring))         return new list<searchresult>();      var query = new multifieldqueryparser(         lucene.net.util.version.lucene_30,         new string[] { "body", "secondaryreferences" },         analyzer     ).parse(querystring);      var indexreader = directoryreader.open(         directory: index,         readonly: true);     var indexsearcher = new indexsearcher(indexreader);     var resultscollector = topscoredoccollector.create(         numhits: maxresults,         docsscoredinorder: true     );     indexsearcher.search(         query: query,         results: resultscollector     );     totalresults = resultscollector.totalhits;     var result = new list<searchresult>();     foreach (var scoredoc in resultscollector.topdocs().scoredocs)     {         var snippets = new list<searchresultsnippet>();         var doc = indexsearcher.doc(scoredoc.doc);         var searchresult = new searchresult(             type: doc.get("type"),             id: doc.get("id"),             snippets: snippets         );         result.add(searchresult);     }     return result; } 

in order able access text adjacent match, need store termvectors position , offset information @ indexing time, can use retrieve surrounding words.

see http://searchhub.org/2009/05/26/accessing-words-around-a-positional-match-in-lucene/ detailed explanation.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -