0

我有一个多值的名称字段,我必须在列表中找到匹配值的索引。

DOC example:

profile_id: 1
names: [ "My name", "something", "My second name", "My nickname"]

询问:

profile_id:1 AND names:"My secon name"~

预期结果:

my doc, and the index of the matched, 2

可能吗?

4

1 回答 1

0

SpanTermQuery与 TermQuery 一样匹配文档,但它还跟踪出现在同一文档中的相同术语的位置。

Spans positionInfoForAllMatchingDocs = spanQuery.getSpans(..arguments..);
int position = -1;
while(positionInfoForAllMatchingDocs.next()){
      position = positionInfoForAllMatchingDocs.start() // Returns the start position of the current match.
      System.out.println("Found match in the document with id: " + positionInfoForAllMatchingDocs.doc() + " at position: " + position); // You obviously want to replace this sysout with something elegant.
}
  • 确保您计划为其检索位置信息的字段已使用 Field.TermVector.WITH_POSITIONS 或 Field.TermVector.WITH_POSITIONS_AND_OFFSETS 进行索引。
于 2013-03-10T22:40:53.257 回答