简体   繁体   English

获取Lucene的确切短语索引

[英]Get exact phrase index in lucene

I need to get an index of exact phrase in lucene. 我需要获取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. 这个termFreqVector.indexOf(searcWord)我返回搜索词的索引。

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. 如果我将一个短语传递给termFreqVector,它将始终返回-1 ,但我100%确信该短语存在。 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 . 例如,如果您的短语是president obama ,则需要找到president所有位置i ,其中在i+1处的偏移量是obama

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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