简体   繁体   中英

Get exact phrase index in lucene

I need to get an index of exact phrase in lucene. The one word's index I get using this:

TermFreqVector termFreqVector = reader.getTermFreqVector(docId, "content");
TermPositionVector termPositionVector = (TermPositionVector) termFreqVector;
int termIndex = termFreqVector.indexOf(searcWord);

This termFreqVector.indexOf(searcWord) returns me an index of a search word.

The problem is that I need to search a phrase, and need to get index of it. If I pass a phrase to termFreqVector it always returns me -1 , but I am 100% sure that the phrase exists. Is there any solution for this?

You need to do it manually. For example, if your phrase is president obama , you need to find all positions i of president where the term at offset i+1 is obama .

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