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 に答える