Hi,=0AI have the same problem.=0AThis is useful when you try to extract the=
contexts (terms before and after) of a certain term (for example).=0AI fou=
nd a solution but it performs badly: when you try to retrieve those context=
s you have to re-tokenize the documents containing the given term (i.e. "so=
ccer") and you have to keep the before and after tokens using TokenStream a=
nd the current position. Re-tokenizing could be ok on small files, but on l=
arge files it induces a bad performance of the applications.=0AAny differen=
t solution is welcome.=0A=0ACatalin.=0A=0A----- Original Message ----=0AFro=
m: NicolasLalev=E9e <nicolas.lalevee@anyware-tech.com>=0ATo: java-user@luce=
ne.apache.org=0ASent: Tuesday, October 3, 2006 1:04:20 AM=0ASubject: Re: ge=
t terms by positions=0A=0ALe Lundi 02 Octobre 2006 23:06, Renzo Scheffer a =
=E9crit :=0A> Hi,=0A>=0A>=0A>=0A> can anybody be so kind to tell me if it i=
s possible to search a Term by its=0A> position?=0A>=0A>=0A>=0A> I search a=
term (for excample "soccer") and get back the DocId's and=0A> positions as=
follows:=0A>=0A>=0A>=0A>=0A>=0A> TermPositions termPos =3D reader.termPosi=
tions(new=0A> Term("contents","soccer"));=0A>=0A> while(termPos.next()){=0A=
>=0A> int freq =3D termPos.freq();=0A>=0A> for(int i=3D0; i<freq; i++){=0A>=
=0A>=0A>=0A> int docNumber =3D termPos.doc();=0A>=0A> int posit=
ion =3D termPos.nextPosition();=0A>=0A> System.out.println("DocId: "+docNum=
ber+"; Pos:"+position);=0A>=0A> }=0A>=0A>=0A>=0A>=0A>=0A>=0A>=0A>
Output:=
=0A>=0A>=0A>=0A> DocId: 0; Pos: 1=0A>=0A> DocId: 0; Pos: 4=0A>=0A>
DocId: 0=
; Pos: 7=0A>=0A> DocId: 1; Pos: 3=0A>=0A> DocId: 1; Pos: 7=0A>=0A>=0A>=0A>
=
Now I try to get back terms, one position before/after "soccer". I=0A> cons=
idered to take the=0A>=0A> Position and increase or decrease it. But I can'=
t find a way to get back a=0A> term, according to the given Position.=0A>=
=0A> Can anybody help me?=0A>=0A=0AI think this is a non-sense to try to fi=
nd a term. In Lucene, you search with =0Aa term, you are not trying to get =
some. Basically, in Lucene, you have a list =0Aof term pointing on document=
s, not the reverse.=0A=0AMaybe if you explain why you are trying to do that=
, we can find a better way =0Ato do it.=0A=0ANicolas=0A=0A-----------------=
----------------------------------------------------=0ATo unsubscribe, e-ma=
il: java-user-unsubscribe@lucene.apache.org=0AFor additional commands, e-ma=
il: java-user-help@lucene.apache.org=0A=0A=0A=0A=0A=0A=0A=0A
|