lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brisbart Franck <Franck.Brisb...@kelkoo.net>
Subject Re: NPE when using explain
Date Thu, 04 Dec 2003 10:46:22 GMT
I think you have some documents which don't contain all the fields.
Something like:
docA : field1=valueA1 ; field2=valueA2; field3=valueA3;
docB : field1=valueB1 ; field3=valueB3;

docB will generate a NPE when the 'explain' will treat it because of the 
missing 'field2'
I think it's a little bug that can happen when the index is not 
'consistent' (ie all documents have the same fields).
Check your index to see if it's the case. Note that even if only 1 
document contains a field 'toto', this field is added to the list of the 
index fields.

Franck


Dror Matalon wrote:
> Hi,
> 
> I'm trying to use IndexSearcher.explain(Query query, int doc) and am
> getting a NPE. If I remove the "explain" the search works fine.
> I poked a little at the TermQuery.java code, but I can't really tell
> what's causing the exception.
> 
> This is with 1.3rc3
> 
> 
> Exception in thread "main" java.lang.NullPointerException at
> org.apache.lucene.search.TermQuery$TermWeight.explain(TermQuery.java:142) at
> org.apache.lucene.search.BooleanQuery$BooleanWeight.explain(BooleanQuery.java:186) at
> org.apache.lucene.search.IndexSearcher.explain(IndexSearcher.java:196)
> at LuceneCli.search(LuceneCli.java:78)
> at LuceneLine.handleCommand(LuceneLine.java:188)
> at LuceneLine.<init>(LuceneLine.java:117)
> at LuceneLine.main(LuceneLine.java:136)
> 
> The area of the code that caused this.
> 
>     Hits hits = initSearch(queryString);
>     System.out.println(hits.length() + " total matching documents");
> 
>     final int HITS_PER_PAGE = 10;
>     message ("--------------------------------------");
>     for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
>       int end = Math.min(hits.length(), start + HITS_PER_PAGE);
>       for (int ii = start; ii < end; ii++) {
>         Document doc = hits.doc(ii);
>         message ("---------------- " + ii + " score:" + hits.score(ii) + "---------------------");
>         if (explain) {
>           Explanation exp = searcher.explain(query, ii);
>           message("Explanation:" + exp.toString());
>         }
>         printHit(doc);
>       }
> 
> 
> Regards,
> 
> Dror
> 



-- 
Franck Brisbart
R&D
http://www.kelkoo.com


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


Mime
View raw message