lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Vitaly_Arte...@McAfee.com>
Subject RE: Lucene 4.0.0 - find term position.
Date Fri, 07 Dec 2012 14:24:24 GMT
I try to use or  Terms tfvector = reader.getTermVector(docId, "contents"); or  Fields fields
= reader.getTermVectors(docId);
but I get null from these calls.
What is wrong?

-----Original Message-----
From: lukai [mailto:lukai1984@gmail.com] 
Sent: Friday, December 07, 2012 2:50 AM
To: java-user@lucene.apache.org
Subject: Re: Lucene 4.0.0 - find term position.

terms = fileds.terms(...);
termsEnum = terms.iterator(null);
termsEnum.seekExat(...);
docsAndPositionsEnum docsPosEnum = termsEnum.docsAndPositions(...);

You can get the information in "docsPosEnum".


On Thu, Dec 6, 2012 at 2:28 AM, <Vitaly_Artemov@mcafee.com> wrote:

> Hi all,
> I am new with Lucene.
> I try to understand how can I find the term position.
>
> I use following code to index documents:
> ...
>                 IndexWriter writer = new IndexWriter(mIndexDir, mIwc);
>                 FileInputStream fis;
>                 fis = new FileInputStream(file); Document doc = new 
> Document(); Field pathField = new StringField("path", file.getPath(), 
> Field.Store.YES);
>                 doc.add(pathField);
> doc.add(new TextField("contents", new BufferedReader(new 
> InputStreamReader(fis, "UTF-16LE")))); writer.updateDocument(new 
> Term("path", file.getPath()), doc); fis.close(); writer.close(); ...
>
> To search I use following code:
> ...
> IndexReader reader = DirectoryReader.open( mIndexDir ); IndexSearcher 
> searcher = new IndexSearcher(reader); QueryParser parser = new 
> QueryParser(Version.LUCENE_40, "contents", mAnalyzer); Query query = 
> parser.parse(aQuery);
>
> TopScoreDocCollector collector = TopScoreDocCollector.create(100, 
> true); searcher.search(query, collector); ScoreDoc[] hits = 
> collector.topDocs().scoreDocs;
>
> for(int i=0;i<hits.length;++i) {
>                 int docId = hits[i].doc;
>                 Document d = searcher.doc(docId); } ...
> How can I find positions of my query string in the indexed documents.
>
> Thanks, Vitaly
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message