2
votes

Hello I am new to lucene I have created the index using lucene. I am adding two fields filename and contents of the file to lucene index. but when i am searching from index i am able to get the occurrence of a query word and files name those contains the query word. I am not able to view the contents of files for which i have created the index can anybody help please thanks in advance

Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory,true);
QueryParser parser = 
    new QueryParser(Version.LUCENE_30,"contents", new SimpleAnalyzer());
Query query = parser.parse(queryStr);
query.setBoost((float)1.5);
TopDocs topDocs = searcher.search(query, maxHits);
ScoreDoc[] hits = topDocs.scoreDocs;
arr= new String[hits.length];
for ( i = 0; i <hits.length; i++) {
    int docId = hits[i].doc;
    Document d = searcher.doc(docId);
    arr[i]=d.get("filename");
}

i am using this code for reading the index.

1

1 Answers

3
votes

To be brief, there are two attributes related to feeding the fields to the Lucene index.

1) Indexed : Only searchable, but irretrievably lost, i.e. the content cannot be read back from the index.

2) Stored : Content in these fields can be retrieved without any loss.

I think, your "filename" field is "Indexed" & "Stored", whereas the "contents" is certainly NOT "Stored".

The above are specified while Indexing the data.

You may refer to : 1.3 Adding a Document/object to Index