lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "miki sun" <>
Subject Re: doc.get("contents")
Date Fri, 07 Apr 2006 10:46:41 GMT
Thanks Chris

I just realize the "contents" in the index is not the "contents" in the 
original document.


----Original Message Follows----
From: Chris Hostetter <>
Subject: Re: doc.get("contents")
Date: Thu, 6 Apr 2006 14:58:25 -0700 (PDT)

Fields, by default, are not stored.  if you look at the
file in the demo, you should see that the contents field is created this

     // Add the contents of the file to a field named "contents".  Specify a 
     // so that the text of the file is tokenized and indexed, but not 
     // Note that FileReader expects the file to be in the system's default 
     // If that's not the case searching for special characters will fail.
     doc.add(new Field("contents", new FileReader(f)));

..since it is not stored, the call to doc.get("contents") returns null ...
you're not checking for it to be null, before passing it to StringReader,
so you get the null pointer exception then.

You could change the code to made contents a stored field, but that would
make you index much bigger.  you could also open the orriginal file on
disk, and pass it to the analyzer for highlighting instead.

: Date: Thu, 06 Apr 2006 20:19:24 +0000
: From: miki sun <>
: Reply-To:
: To:
: Subject: doc.get("contents")
: Dear all
: I got a java.lang.NullPointerException at
:<init>( error when processing 
: following code:
: for (int i = 0; i < theHits.length(); i++)
: {
: Document doc = theHits.doc(i);
: String contents = doc.get("contents") ;
: TokenStream tokenStream = analyzer.tokenStream( "contents", new
: StringReader(contents)) ;
: System.out.println(theHighlighter.getBestFragment(tokenStream, contents));
: }
: I used demo.IndexFiles to index my directory. Who can tell me what's 
: Thanks a lot!
: Miki
: ---------------------------------------------------------------------
: To unsubscribe, e-mail:
: For additional commands, e-mail:


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message