You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Patricio Galeas <ga...@informatik.uni-siegen.de> on 2005/04/10 17:52:45 UTC
Terms & Postion from Hits ...
Hello,
I am new with Lucene. I have following problem.
When I execute a search I receive the list of document Hits.
I get without problem the content of the documents too:
for (int i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
System.out.println(doc.get("content"));
}
Now, I would like to obtain the List of all Terms (and their corresponding
position) from each document (hits.doc(i)).
I have experimented creating a second index with the founded documents
(Hits), and analyze it to obtain this information, but the algorithm work
very slow.
Do you have another idea?
Thank You for your help!
Re: Terms & Postion from Hits ...
Posted by Maik Schreiber <bl...@blizzy.de>.
> Now, I would like to obtain the List of all Terms (and their corresponding
> position) from each document (hits.doc(i)).
Try IndexReader.getTermFreqVector(), which will return an instance of
TermPositionVector when the corresponding field has been indexed with
storeTermVector==true.
--
Maik Schreiber * http://www.blizzy.de
GPG public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x1F11D713
Key fingerprint: CF19 AFCE 6E3D 5443 9599 18B5 5640 1F11 D713
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
AW: Terms & Postion from Hits ...
Posted by Patricio Galeas <ga...@informatik.uni-siegen.de>.
Hello!
Do You mean:
I must compile the latest classes of
/lucene/java/trunk/src/java/org/apache/lucene/index (Rev.159229)
and
/lucene/java/trunk/src/java/org/apache/lucene/document (Rev.150682)
and actualize my actual version of Lucene?
Thank You for your help!!
Patricio
-----Ursprüngliche Nachricht-----
Von: Erik Hatcher [mailto:erik@ehatchersolutions.com]
Gesendet: Montag, 11. April 2005 15:05
An: java-user@lucene.apache.org
Betreff: Re: Terms & Postion from Hits ...
On Apr 10, 2005, at 11:52 AM, Patricio Galeas wrote:
> Hello,
> I am new with Lucene. I have following problem.
> When I execute a search I receive the list of document Hits.
> I get without problem the content of the documents too:
>
> for (int i = 0; i < hits.length(); i++) {
> Document doc = hits.doc(i);
> System.out.println(doc.get("content"));
> }
>
> Now, I would like to obtain the List of all Terms (and their
> corresponding
> position) from each document (hits.doc(i)).
Lucene 1.4.x contains a term vector feature (see the javadocs for
Field) that you can enable. This does not give you position information
though. In the latest codebase (obtained via Subversion) the term vector
feature has been enhanced to allow (optionally) the capturing of term
positions and then also term offsets.
I recommend you try out the latest codebase for these features.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Terms & Postion from Hits ...
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Apr 10, 2005, at 11:52 AM, Patricio Galeas wrote:
> Hello,
> I am new with Lucene. I have following problem.
> When I execute a search I receive the list of document Hits.
> I get without problem the content of the documents too:
>
> for (int i = 0; i < hits.length(); i++) {
> Document doc = hits.doc(i);
> System.out.println(doc.get("content"));
> }
>
> Now, I would like to obtain the List of all Terms (and their
> corresponding
> position) from each document (hits.doc(i)).
Lucene 1.4.x contains a term vector feature (see the javadocs for
Field) that you can enable. This does not give you position
information though. In the latest codebase (obtained via Subversion)
the term vector feature has been enhanced to allow (optionally) the
capturing of term positions and then also term offsets.
I recommend you try out the latest codebase for these features.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Terms & Postion from Hits ...
Posted by Andy Roberts <ma...@andy-roberts.net>.
I've managed something like this from a slightly different perspective.
IndexReader ir = new IndexReader(yourIndex);
String searchTerm = "word";
TermPositions tp = ir.termPositions(new Term("contents", searchTerm);
tp.next();
int termFreq = tp.freq();
System.out.print(currentTerm.text());
for (int i=0; i < termFreq; i++) {
System.out.print(" " + tp.nextPosition());
}
System.out.println();
ir.close();
This will print out something like:
word 1 67 104 155
Where the term "word" occurs at positions 1, 67, 104 and 155 in the field
"contents" of the index ir.
HTH,
Andy Roberts
On Sunday 10 Apr 2005 15:52, Patricio Galeas wrote:
> Hello,
> I am new with Lucene. I have following problem.
> When I execute a search I receive the list of document Hits.
> I get without problem the content of the documents too:
>
> for (int i = 0; i < hits.length(); i++) {
> Document doc = hits.doc(i);
> System.out.println(doc.get("content"));
> }
>
> Now, I would like to obtain the List of all Terms (and their corresponding
> position) from each document (hits.doc(i)).
>
> I have experimented creating a second index with the founded documents
> (Hits), and analyze it to obtain this information, but the algorithm work
> very slow.
>
> Do you have another idea?
>
> Thank You for your help!
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org