lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vidya Kanigiluppai Sivasubramanian <vidya...@hcl.com>
Subject Finding match term positions in the document
Date Fri, 28 Oct 2011 08:48:30 GMT
Hi,

I am using lucene 2.4.1 in my project.
I need to display the search results when searched for a particular term and on selecting
an item in the result page, I need to display the document where the term was found highlighting
the match terms in the display.
For this I need to know the match term positions in the source document used for indexing.
I tried using TermPositionVectors but it doesn't seem to be useful.
It does not return the position of the term in the document used for indexing.
Is there any API available for this in 2.4.1 or do I need to upgrade to the latest version
of lucene?

This is my code snippet:

                  Term term = new Term("contents", searchTerm);
                  TermDocs docs = reader.termDocs(term);
                  docs.seek(term);
                  docs.skipTo(docId);
                  TermPositions termpos = reader.termPositions(term);
                  for ( int k = 0; k < docs.freq(); k++ )
                  {
                        termposx[i][k] = termpos.nextPosition();
                  }

Thanks in Advance,
Vidya K S


________________________________
::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named
recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or
opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of
HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and
/ or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited.
If you have
received this email in error please delete it and notify the sender immediately. Before opening
any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------

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