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]