如何根据Lucene中的TermPosition获取术语?

如何根据Lucene中的TermPosition获取术语?,lucene,term,Lucene,Term,我的问题是,使用termposx,如何根据termposx数组获取术语?Zincup:termposx有{7,19,34}。8点或9点的术语是什么?如何访问它 TermPositionVector.getTermPositions()返回找到术语的位置数组。 术语由其编号出现在从indexOf方法获得的术语字符串数组中的索引标识 所以在{7,19,34}的多个位置出现的是同一个项 使用TermPositionVector,您可以访问“找到每个术语的位置”,但不能以其他方式访问 恐怕,你必须迭代才

我的问题是,使用termposx,如何根据termposx数组获取术语?

Zincup:termposx有{7,19,34}。8点或9点的术语是什么?如何访问它

TermPositionVector.getTermPositions()返回找到术语的位置数组。

术语由其编号出现在从indexOf方法获得的术语字符串数组中的索引标识

所以在{7,19,34}的多个位置出现的是同一个项

使用TermPositionVector,您可以访问“找到每个术语的位置”,但不能以其他方式访问


恐怕,你必须迭代才能找到8,9位置的项。我将进一步研究API,如果我找到了解决方案,请告诉您。

在给定的情况下,“querystr”是一个术语,因为它用于检索termposx。例如,感谢termposx有{7,19,34}。8点或9点的术语是什么?如何访问它?
Here are some code to access terms in a Lucene document:
int docId = hits[i].doc;  
TermFreqVector tfvector = reader.getTermFreqVector(docId, "contents");  
TermPositionVector tpvector = (TermPositionVector)tfvector;  
// this part works only if there is one term in the query string,  
// otherwise you will have to iterate this section over the query terms.  
int termidx = tfvector.indexOf(querystr);  
int[] termposx = tpvector.getTermPositions(termidx);  
TermVectorOffsetInfo[] tvoffsetinfo = tpvector.getOffsets(termidx);