hard to say. You should get a copy of Luke and inspect your index to see if what you think you put there is actually there. When you added data to your index, did you perform a commit?
Best Erick On Wed, Jun 8, 2011 at 2:45 AM, Pranav goyal <pranavgoyal40...@gmail.com> wrote: > There is one field DocId which I am storing as well as indexing and DocId > and it's value is 00000341 > > But the search results are giving me 0 results. > Is there any error in my code for searching? > > > > > StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31); > IndexSearcher searcher = null; > try { > searcher = new IndexSearcher(FSDirectory.open(indexDir)); > } catch (CorruptIndexException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } > QueryParser parser = new > QueryParser(Version.LUCENE_31,"text",analyzer); > > String[] queryStrings = new String[] { "00000341", > "9346868468" }; > TopDocs results = null; > for (String queryString : queryStrings) { > System.out.println("searching for: " + queryString); > Query query1; > try { > query1 = parser.parse(queryString); > try { > results = searcher.search(query1,10); > } catch (IOException e) { > e.printStackTrace(); > } > } catch (ParseException e) > e.printStackTrace(); > } > > System.out.println("total hits: " + results.totalHits); > ScoreDoc[] hits = results.scoreDocs; > Document doc = null; > for (ScoreDoc hit : hits) > { > > try { > doc = searcher.doc(hit.doc); > } catch (CorruptIndexException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } > System.out.printf("%5.3f %sn", hit.score, > doc.get("DocId")); > } > > > > On Wed, Jun 8, 2011 at 11:47 AM, Pranav goyal > <pranavgoyal40...@gmail.com>wrote: > >> Thanks Anshum >> >> >> On Wed, Jun 8, 2011 at 11:40 AM, Anshum <ansh...@gmail.com> wrote: >> >>> Hi Pranav, >>> The result would be a list of document ids, which can be used to retrieve >>> the document (Using an indexreader). Once you have the document, you could >>> fetch 'ANY' of the 'STORED' fields from the index for your purpose. >>> Directly, you'd not receive either the key field or any other field from >>> the >>> 'search' method. >>> Also, I'd suggest you to grab a copy of Lucene in Action 2nd Edition as >>> it'd >>> help you a lot in understanding the way Lucene works/is used. >>> >>> -- >>> Anshum Gupta >>> http://ai-cafe.blogspot.com >>> >>> >>> On Wed, Jun 8, 2011 at 11:00 AM, Pranav goyal <pranavgoyal40...@gmail.com >>> >wrote: >>> >>> > Hi all, >>> > >>> > I am getting confused in this thing, >>> > >>> > Let say I make a lucene index using a document having a key field (which >>> I >>> > am storing as well as indexing) >>> > and rest of my fields I am just indexing. >>> > >>> > When I make some query what would be my result? >>> > Will it be the field which I am storing or it can be anything? >>> > >>> >> >> >> >> -- >> I'm very responsible, when ever something goes wrong they always say I'm >> responsible -- >> > > > > -- > I'm very responsible, when ever something goes wrong they always say I'm > responsible -- > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org