lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Renzo Scheffer" <>
Subject get terms by positions
Date Mon, 02 Oct 2006 21:06:40 GMT


can anybody be so kind to tell me if it is possible to search a Term by its


I search a term (for excample "soccer") and get back the DocId's and
positions as follows:



TermPositions termPos = reader.termPositions(new Term("contents","soccer"));


int freq = termPos.freq();

for(int i=0; i<freq; i++){


      int docNumber = termPos.doc();

      int position = termPos.nextPosition();

System.out.println("DocId: "+docNumber+"; Pos:"+position);







DocId: 0; Pos: 1

DocId: 0; Pos: 4

DocId: 0; Pos: 7

DocId: 1; Pos: 3

DocId: 1; Pos: 7


Now I try to get back terms, one position before/after "soccer". I
considered to take the 

Position and increase or decrease it. But I can't find a way to get back a
term, according to the given Position.

Can anybody help me? 


Thanks, Renzo


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message