【问题标题】:How to get the term based on termPostion in Lucene?如何根据 Lucene 中的 termPostion 获取术语?
【发布时间】:2013-02-20 11:22:43
【问题描述】:
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);  

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

【问题讨论】:

  • 在给定的情况下,'querystr' 是术语,因为它用于检索 termposx。
  • 谢谢,例如 termposx 有 {7, 19, 34}。 8 或 9 的术语是什么?如何访问它?

标签: lucene term


【解决方案1】:

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

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

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

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

使用 TermPositionVector,您可以访问“找到每个术语的位置”,但反之则不行。

恐怕,您必须迭代才能在 8,9 位置找到该术语。如果我找到解决方案,我会进一步探索 API 并通知您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2016-06-18
    • 2019-03-17
    • 2012-02-14
    相关资源
    最近更新 更多