简体   繁体   中英

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

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();

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM