I agree.

Thanks.


On 9/13/06, Ronnie Kolehmainen <[EMAIL PROTECTED]> wrote:

This might be related to filesystem, internal lucene buffering/caching,
or practically anything that an implementor does not need to have
knowledge of.

The only thing that you, the implementor, *do* need to know is that you
should *not* access a Hits object after the searcher is closed ;)

/Ronnie



Huinan wrote:
> Thanks, Ronnie. But why it works in some cases (when there is a small
> number
> of documents inside the index) ?
>
>
> On 9/13/06, Ronnie Kolehmainen <[EMAIL PROTECTED]> wrote:
>
>>
>> Do not close the searcher until you are done with the Hits object.
>>
>> See the javadocs for Searchable.close()
>>
>>
http://lucene.apache.org/java/docs/api/org/apache/lucene/search/Searchable.html#close()
>>
>>
>>
>> /Ronnie
>>
>> Huinan wrote:
>> > Hi,
>> >
>> > I'm having a weird problem:
>> >
>> > I created an index using IndexWriter. Then I had a piece of code
which
>> > searches the index, then print out a particular field of the first
>> document
>> > of the hits.(See the following code) As simple as that.
>> >
>> >        Hits hits = IndexSearchUtil.getHits(defaultIndexLocation, "A",
>> "a");
>> >        System.out.println(hits.length());  // This prints 1.
>> >        Document doc = hits.doc(0);       // <------But this will
throw
>> an
>> > IOException, and this is the problem.
>> >        System.out.println(doc.get("A"));
>> >
>> > The strange thing is that it DOES NOT ALWAYS throw an IOException.
When
>> I
>> > have a small number (tens) of index entries, this works fine. But
>> beyond
>> a
>> > certain threshold, It begins to throw up. :-(
>> >
>> > Does anyone have the same problem? or could suggest what might have
>> gone
>> > wrong?
>> >
>> > Thanks a lot!
>> >
>> >
>> > Regards.
>> >
>> > Huinan
>> >
>> >
>> > Appendix
>> > (inside IndexSearchUtil class)
>> >    public static Hits getHits(String indexLocation, String fieldName,
>> >            String key) throws IOException {
>> >        return getHits(indexLocation, fieldName, key, true);
>> >    }
>> >
>> >    public static Hits getHits(String indexLocation, String fieldName,
>> >            String key, boolean fieldTokenized) throws IOException {
>> >        IndexSearcher searcher = new IndexSearcher(indexLocation);
>> >        if (!fieldTokenized)
>> >            key = "\"" + key + "\"";
>> >        QueryParser parser = new QueryParser(fieldName, new
>> > KeywordAnalyzer());
>> >        Query query;
>> >        try {
>> >            query = parser.parse(key);
>> >            Hits hits = searcher.search(query);
>> >            searcher.close();
>> >            return hits;
>> >        } catch (ParseException e) {
>> >            e.printStackTrace();
>> >            return null;
>> >        }
>> >    }
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>

--
________________________________________

   Ronnie Kolehmainen
   Systems Developer
   Electronic Publishing Centre
   Uppsala University Library
   +46 (0)18 471 5847
   mailto:[EMAIL PROTECTED]
________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to