问题
How could I get offsets for the tokens that has to be searched in Lucene.net?I am using FastVector Highlighter for highlighting a text?
Note:I have already got the offsets of all the token that has been indexed using Standard Analyzer and now I would be interested in getting the offsets of the particular token?
testhighlighter tst = new testhighlighter();
Lucene.Net.Analysis.Token net = tokenstream.Next();
int startoffset = net.StartOffset();
int endoffset = net.EndOffset();
回答1:
You can try TermVectorMapper to get positions and offsets of terms.
http://permalink.gmane.org/gmane.comp.jakarta.lucene.net.user/3203
class TVM: TermVectorMapper
{
public override void SetExpectations(string field, int numTerms, bool storeOffsets, bool storePositions)
{
}
public override void Map(string term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
{
}
}
TVM tvm = new TVM();
reader.GetTermFreqVector(docID, field, tvm);
来源:https://stackoverflow.com/questions/6827959/finding-offsets-of-a-search-term-in-lucene-net-c