lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Newbie Search Question
Date Fri, 24 Nov 2006 14:01:20 GMT
If we're still dealing with StringReader(text) throwing an error.... It
really shouldn't unless the document has no field named "contents". Here's
what I'd do...

Get a copy of Luke (google luke lucene) to examine your index.
Figure out what the document ID is that you're blowing up on and look at it
in Luke to be sure that there's text in the contents field.
Watch case etc.

You shouldn't be getting a null here unless 1> your doc ID is not in your
index or 2> your document doesn't have such a field.

And how are you storing your date? Field.Store.YES? NO? COMPRESSED?

Best
Erick

On 11/23/06, sirakov <sirakov@gmail.com> wrote:
>
>
>
> Erick Erickson wrote:
> >
> > So why not assign a string to "text" and try it again? Or show us the
> code
> > where you expect the text variable to get a value.....
> >
> > Erick
> >
> >
>
> I`m sorry that was a miss from my side.
>
> I've tried to put the simple code into SearchFiles, between
>
> Hits hits = searcher.search(query);
>
> and
>
> String path = doc.get("path");
>
> Here the code:
>
>       Highlighter highlighter = new Highlighter(new QueryScorer(query));
>
>
>
>       if (repeat > 0) {                           // repeat & time as
> benchmark
>         Date start = new Date();
>         for (int i = 0; i < repeat; i++) {
>           hits = searcher.search(query);
>         }
>         Date end = new Date();
>         System.out.println("Time: "+(end.getTime()-start.getTime())+"ms");
>       }
>
>       System.out.println(hits.length() + " total matching documents");
>
>       final int HITS_PER_PAGE = 10;
>       for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
>         int end = Math.min(hits.length(), start + HITS_PER_PAGE);
>         for (int i = start; i < end; i++) {
>
>           if (raw) {                              // output raw format
>             System.out.println("doc="+hits.id(i)+" score="+hits.score(i));
>             continue;
>           }
>
>           Document doc = hits.doc(i);
>
>           String text = hits.doc(i).get(field); //String field =
> "contents";
>           TokenStream tokenStream = analyzer.tokenStream(field, new
> StringReader(text));
>           // Get 3 best fragments and seperate with a "..."
>           String result = highlighter.getBestFragments(tokenStream, text,
> 3,
> "...");
>
>
>           String path = doc.get("path");
>           if (path != null) {
>             System.out.println((i+1) + ". " +
> path);System.out.println("\t"+result);
>             String title = doc.get("title");
>             if (title != null) {
>               System.out.println("   Title: " + doc.get("title"));
>             }
>           } else {
>             System.out.println((i+1) + ". " + "No path for this
> document");
>           }
>         }
>
> The bolded text was added by me. I hope, i have made the changes in the
> right file :)
> --
> View this message in context:
> http://www.nabble.com/Newbie-Search-Question-tf2667479.html#a7513261
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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