2013-03-10 42 views
0

我有一個多值字段的名稱,我必須找到列表中匹配值的索引。Lucene在多值字段中找到索引?

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

你試過這個查詢嗎?因爲多值字段的處理方式相同。可能是你需要澄清問題究竟出了什麼問題? – Dewfy 2013-03-10 16:50:52

+0

expetcted結果意味着我需要什麼,而是響應只是文檔,而不知道哪個名稱的索引匹配 – rodi 2013-03-10 17:19:43

+0

MultiFieldQueryParser - 允許您指定儘可能多的名稱。 – Dewfy 2013-03-10 17:26:31

回答

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索引。