我有一个多值的名称字段,我必须在列表中找到匹配值的索引。
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
有可能吗?
答案 0 :(得分: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.
}