lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ROSHAN NAVENDRA" <rnaven...@ccnetwork.com.au>
Subject Re: Accessing the "contents" field
Date Thu, 14 Mar 2002 06:34:18 GMT
It is being added as a Text field.... which is stored i gather. Is is also being added as as
a Reader.... this might be the problem I am not sure.

Here is my code, can anybody please help me.

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.*;

import java.io.*;


public class IndexFiles { 
  // usage: IndexFiles index-path file . . . 
  public static void main(String[] args) throws Exception {
    String indexPath = args[0];
    IndexWriter writer;

    writer = new IndexWriter(indexPath, new SimpleAnalyzer(), false);
    for (int i=1; i<args.length; i++) {
      System.out.println("Indexing file " + args[i]);
      InputStream is = new FileInputStream(args[i]);
      
     

      // We create a Document with two Fields, one which contains
      // the file path, and one the file's contents.  
      Document doc = new Document();
      doc.add(Field.UnIndexed("path", args[i]));
      doc.add(Field.Text("body", (Reader) new InputStreamReader(is)));

      writer.addDocument(doc);
      is.close();
    };

    writer.close();
  }
}



>>> otis_gospodnetic@yahoo.com 03/14/02 03:21PM >>>
Make sure that you added it to the index as a stored field, and not
just indexed.  Look at the Javadoc for Field class to see different
field types.

Otis

--- ROSHAN NAVENDRA <rnavendra@ccnetwork.com.au> wrote:
> Hi,
> 
> I would like to access the contents field of a document, fo rexample
> 
> doc(i).get("contents")
> 
> this should return a String (am i right?) but when I print it out I
> find that it is a Null. How do I go about accessing the contents of
> the file????
> 
> Rosh.
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:lucene-user-help@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/ 

--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message