You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by xuemei li <xl...@cs.odu.edu> on 2004/08/03 16:57:38 UTC

search exception in servlet!Please help me

hi,all,

I am using lucene to search.When I use console to run my code it works
fine.But after I put my code to a servlet.It will throw exception.Here is
my exception code:
         Document doc= hits.doc(i);-->exception
But I can use the following code to get the hits.length() value.
    out.println("<center><p>There are  "+hits.length()+"  matches for the
word you have entered !</p></center>");

What's the problem?Any reply will be appreciated.

thanks,
Xuemei Li



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


Re: search exception in servlet!Please help me

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
My deepest apologies - I totally misspoke with my post yesterday.  
Chris, and the others, are correct - I wasn't thinking clearly and was 
confusing IndexReader.document() with Hits.doc().

So, as far as the exception goes - perhaps your servlet does not have 
access to the index because of permissions.  Maybe you're using a 
different version of Lucene between the command-line and your web 
application?

	Erik

On Aug 4, 2004, at 3:14 AM, Christiaan Fluit wrote:

> Erik Hatcher wrote:
>
>> Where did you get 'i'?   Keep in mind that using Hits.doc(n) intends 
>> 'n' to be a document *id*, not the iteration through the Hits 
>> collection.  This is a very common mistake, and I'm guessing one 
>> you've made here.
>
> I believe the Javadoc (as well as my own experience) tells otherwise:
>
> "public final Document doc(int n) throws IOException
>
>     Returns the stored fields of the nth document in this set."
>
>
> Regards,
>
> Chris
> --
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org


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


Re: search exception in servlet!Please help me

Posted by Christiaan Fluit <ch...@aduna.biz>.
Erik Hatcher wrote:

> Where did you get 'i'?   Keep in mind that using Hits.doc(n) intends 'n' 
> to be a document *id*, not the iteration through the Hits collection.  
> This is a very common mistake, and I'm guessing one you've made here.

I believe the Javadoc (as well as my own experience) tells otherwise:

"public final Document doc(int n) throws IOException

     Returns the stored fields of the nth document in this set."


Regards,

Chris
--


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


Re: search exception in servlet!Please help me

Posted by Srikanth Balusni <ba...@cs.odu.edu>.
By observing the implementation details of the Hits object lucene, I feel
that  Hits.doc(n) intends 'n' to be the index of the results. So, my
feeling is that progam which Li wrote should work ideally.
Erik, Correct me if I am wrong.
Li, Can you post entire stack trace?

Thanks,
sri


> hi,Erik
>
> But before I put my code to the servlet I can get the correct document
> by following:
> Hits hits=searcher.search(query);
> for (int i=0;i<hits.length(),i++){
> Document doc= hits.doc(i);
> ....
> }
> Could you tell me how you get the document?
>
> thanks,
> Li
>
>> Where did you get 'i'?   Keep in mind that using Hits.doc(n) intends
>> 'n' to be a document *id*, not the iteration through the Hits
>> collection.  This is a very common mistake, and I'm guessing one
>> you've made here.
>>
>> 	Erik
>>
>>
>> On Aug 3, 2004, at 7:49 PM, xuemei li wrote:
>>
>>> Thank you for your reply.
>>> when I want to get the document from hits.It throws
>>> nullpointerexception.But the hits.length() value is not 0.
>>>
>>> thanks,
>>> Xuemei Li
>>>> What is the exception? Is hits null or the index (i) out of bounds?
>>>>
>>>> sv
>>>>
>>>> On Tue, 3 Aug 2004, xuemei li wrote:
>>>>
>>>>> hi,all,
>>>>>
>>>>> I am using lucene to search.When I use console to run my code it
>>>>> works
>>>>> fine.But after I put my code to a servlet.It will throw
>>>>> exception.Here
>>>>> is my exception code:
>>>>>          Document doc= hits.doc(i);-->exception
>>>>> But I can use the following code to get the hits.length() value.
>>>>>     out.println("<center><p>There are  "+hits.length()+"  matches
>>>>> for
>>>>> the
>>>>> word you have entered !</p></center>");
>>>>>
>>>>> What's the problem?Any reply will be appreciated.
>>>>>
>>>>> thanks,
>>>>> Xuemei Li
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>>> For
>>>>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>>  To
>>>> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>>>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
> additional commands, e-mail: lucene-user-help@jakarta.apache.org




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


Re: search exception in servlet!Please help me

Posted by xuemei li <xl...@cs.odu.edu>.
hi,Erik

But before I put my code to the servlet I can get the correct document by
following:
Hits hits=searcher.search(query);
for (int i=0;i<hits.length(),i++){
Document doc= hits.doc(i);
....
}
Could you tell me how you get the document?

thanks,
Li

> Where did you get 'i'?   Keep in mind that using Hits.doc(n) intends
> 'n' to be a document *id*, not the iteration through the Hits
> collection.  This is a very common mistake, and I'm guessing one you've
> made here.
>
> 	Erik
>
>
> On Aug 3, 2004, at 7:49 PM, xuemei li wrote:
>
>> Thank you for your reply.
>> when I want to get the document from hits.It throws
>> nullpointerexception.But the hits.length() value is not 0.
>>
>> thanks,
>> Xuemei Li
>>> What is the exception? Is hits null or the index (i) out of bounds?
>>>
>>> sv
>>>
>>> On Tue, 3 Aug 2004, xuemei li wrote:
>>>
>>>> hi,all,
>>>>
>>>> I am using lucene to search.When I use console to run my code it
>>>> works
>>>> fine.But after I put my code to a servlet.It will throw
>>>> exception.Here
>>>> is my exception code:
>>>>          Document doc= hits.doc(i);-->exception
>>>> But I can use the following code to get the hits.length() value.
>>>>     out.println("<center><p>There are  "+hits.length()+"  matches
>>>> for
>>>> the
>>>> word you have entered !</p></center>");
>>>>
>>>> What's the problem?Any reply will be appreciated.
>>>>
>>>> thanks,
>>>> Xuemei Li
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>> For
>>>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>>  To
>>> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
> additional commands, e-mail: lucene-user-help@jakarta.apache.org




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


Re: search exception in servlet!Please help me

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Where did you get 'i'?   Keep in mind that using Hits.doc(n) intends 
'n' to be a document *id*, not the iteration through the Hits 
collection.  This is a very common mistake, and I'm guessing one you've 
made here.

	Erik


On Aug 3, 2004, at 7:49 PM, xuemei li wrote:

> Thank you for your reply.
> when I want to get the document from hits.It throws
> nullpointerexception.But the hits.length() value is not 0.
>
> thanks,
> Xuemei Li
>> What is the exception? Is hits null or the index (i) out of bounds?
>>
>> sv
>>
>> On Tue, 3 Aug 2004, xuemei li wrote:
>>
>>> hi,all,
>>>
>>> I am using lucene to search.When I use console to run my code it 
>>> works
>>> fine.But after I put my code to a servlet.It will throw 
>>> exception.Here
>>> is my exception code:
>>>          Document doc= hits.doc(i);-->exception
>>> But I can use the following code to get the hits.length() value.
>>>     out.println("<center><p>There are  "+hits.length()+"  matches for
>>> the
>>> word you have entered !</p></center>");
>>>
>>> What's the problem?Any reply will be appreciated.
>>>
>>> thanks,
>>> Xuemei Li
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org 
>>> For
>>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>
>>
>>
>> --------------------------------------------------------------------- 
>> To
>> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org


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


Re: search exception in servlet!Please help me

Posted by xuemei li <xl...@cs.odu.edu>.
Thank you for your reply.
when I want to get the document from hits.It throws
nullpointerexception.But the hits.length() value is not 0.

thanks,
Xuemei Li
> What is the exception? Is hits null or the index (i) out of bounds?
>
> sv
>
> On Tue, 3 Aug 2004, xuemei li wrote:
>
>> hi,all,
>>
>> I am using lucene to search.When I use console to run my code it works
>> fine.But after I put my code to a servlet.It will throw exception.Here
>> is my exception code:
>>          Document doc= hits.doc(i);-->exception
>> But I can use the following code to get the hits.length() value.
>>     out.println("<center><p>There are  "+hits.length()+"  matches for
>> the
>> word you have entered !</p></center>");
>>
>> What's the problem?Any reply will be appreciated.
>>
>> thanks,
>> Xuemei Li
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
>> additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For
> additional commands, e-mail: lucene-user-help@jakarta.apache.org




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


Re: search exception in servlet!Please help me

Posted by Stephane James Vaucher <va...@cirano.qc.ca>.
What is the exception? Is hits null or the index (i) out of bounds?

sv

On Tue, 3 Aug 2004, xuemei li wrote:

> hi,all,
>
> I am using lucene to search.When I use console to run my code it works
> fine.But after I put my code to a servlet.It will throw exception.Here is
> my exception code:
>          Document doc= hits.doc(i);-->exception
> But I can use the following code to get the hits.length() value.
>     out.println("<center><p>There are  "+hits.length()+"  matches for the
> word you have entered !</p></center>");
>
> What's the problem?Any reply will be appreciated.
>
> thanks,
> Xuemei Li
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>


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