Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 9425 invoked from network); 4 Dec 2003 18:11:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 4 Dec 2003 18:11:31 -0000 Received: (qmail 85759 invoked by uid 500); 4 Dec 2003 18:11:18 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 85725 invoked by uid 500); 4 Dec 2003 18:11:18 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 85711 invoked from network); 4 Dec 2003 18:11:18 -0000 Received: from unknown (HELO rwcrmhc12.comcast.net) (216.148.227.85) by daedalus.apache.org with SMTP; 4 Dec 2003 18:11:18 -0000 Received: from lucene.com (c-24-5-145-151.client.comcast.net[24.5.145.151]) by comcast.net (rwcrmhc12) with SMTP id <2003120418111801400bd86ge>; Thu, 4 Dec 2003 18:11:18 +0000 Message-ID: <3FCF78C5.6080803@lucene.com> Date: Thu, 04 Dec 2003 10:11:17 -0800 From: Doug Cutting User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Lucene Users List Subject: Re: NPE when using explain References: <20031204015159.GZ34796@rlx11.zapatec.com> In-Reply-To: <20031204015159.GZ34796@rlx11.zapatec.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This looks like a bug. I think your query contains a term in a field that is not indexed, and hence has no norm value. Perhaps (as Brisbart Franck) suggests, it is indexed in some documents, but not in others. But, in a single IndexReader, if it is indexed in any document, it should have a norm value for all documents. Are you using a MultiSearcher? I can see how this would happen with a MultiSearcher, where different fields exist in the different indexes, and the query contains a term which is only in one of the indexes. Try applying the following patch and tell me if it helps. --- TermQuery.java.~1.7.~ 2003-01-15 11:25:04.000000000 -0800 +++ TermQuery.java 2003-12-04 10:07:46.000000000 -0800 @@ -139,7 +139,10 @@ fieldExpl.addDetail(idfExpl); Explanation fieldNormExpl = new Explanation(); - fieldNormExpl.setValue(Similarity.decodeNorm(reader.norms(field)[doc])); + byte[] fieldNorms = reader.norms(field); + float fieldNorm = + fieldNorms!=null ? Similarity.decodeNorm(fieldNorms[doc]) : 0.0f; + fieldNormExpl.setValue(fieldNorm); fieldNormExpl.setDescription("fieldNorm(field="+field+", doc="+doc+")"); fieldExpl.addDetail(fieldNormExpl); Thanks, Doug 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.(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 > --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org