lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Vitaly_Arte...@McAfee.com>
Subject Lucene 4.0.0 - find term position.
Date Thu, 06 Dec 2012 10:28:40 GMT
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



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