java - Finding the start and end of a match with Lucene -


i find start , end positions of match lucene (version 3.0.2 java) query. seems should able info highlighter or fastvectorhighligher, these classes seem return text fragment relevant text highlighted. there way info, either highlighter or scoredoc itself?

update: found related question: finding position of search hits lucene

but think answer allasso won't work me because queries phrases, not individual terms.

if i'd take code fastvectorhighlighter. relevant code in fieldtermstack:

        list<string> termset = fieldquery.gettermset(fieldname);         vectorhighlightmapper tfv = new vectorhighlightmapper(termset);             reader.gettermfreqvector(docid, fieldname, tfv);  // <-- @ line          string[] terms = tfv.getterms();         foreach (string term in terms)         {             if (!termset.contains(term)) continue;             int index = tfv.indexof(term);             termvectoroffsetinfo[] tvois = tfv.getoffsets(index);             if (tvois == null) return; // return make null snippets             int[] poss = tfv.gettermpositions(index);             if (poss == null) return; // return make null snippets             (int = 0; < tvois.length; i++)                 termlist.addlast(new terminfo(term, tvois[i].getstartoffset(), tvois[i].getendoffset(), poss[i])); 

the major thing there reader.gettermfreqvector(). said, fastvectorhighlighter legwork copy, if want, gettermpositions call should need.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -