Finding offsets of a search term in lucene.net,c#

∥☆過路亽.° 提交于 2019-12-23 02:47:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!