lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: doc.get("contents")
Date Thu, 06 Apr 2006 21:58:25 GMT

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

    // Add the contents of the file to a field named "contents".  Specify a Reader,
    // so that the text of the file is tokenized and indexed, but not stored.
    // Note that FileReader expects the file to be in the system's default encoding.
    // 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 <sun_miki@hotmail.com>
: Reply-To: java-user@lucene.apache.org
: To: java-user@lucene.apache.org
: Subject: doc.get("contents")
:
: Dear all
:
: I got a java.lang.NullPointerException at
: java.io.StringReader.<init>(StringReader.java:33) error when processing the
: 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 wrong?
: Thanks a lot!
:
: Miki
:
:
:
: ---------------------------------------------------------------------
: To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
: For additional commands, e-mail: java-user-help@lucene.apache.org
:



-Hoss


---------------------------------------------------------------------
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