Looks OK to me. You are searching on Item without adding any docs with that field, you could use writer.updateDocument() rather than delete and add, but those are just quibbles and don't explain your searching problem.
Having done most of the hard work, why don't you adapt the code you posted into a simple standalone program or test case that demonstrates the problem. As simple as possible, no external dependencies, clearly showing what you are indexing and what you are searching on, with one search that works and one that doesn't. One warning: using MultiFieldQueryParser with leading wildcards is pretty much guaranteed to be slow on a large index. -- Ian. On Thu, Jun 23, 2011 at 10:08 AM, Pranav goyal <pranavgoyal40...@gmail.com> wrote: > Here's the code which I am implementing (Indexing and Searching codes are in > different files) > > Indexing Part : > > d=new Document(); > File indexDir = new File("index-dir"); > KeywordAnalyzer analyzer = new KeywordAnalyzer(); > > > IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_31, > analyzer); > try { > writer = new IndexWriter(FSDirectory.open(indexDir),conf); > } catch (IOException e1) { > e1.printStackTrace(); > } > String q1 = contract.getDocId(); > String q2 = contract.getDocName(); > String q3 = contract.getCustomer(ctx).getMemberName(); > > Term term = new Term("DocId",contract.getDocId()); > writer.deleteDocuments(term); > > d.add(new > Field("DocId",q1,Field.Store.YES,Field.Index.NOT_ANALYZED)); > d.add(new Field("All",q2,Field.Store.NO,Field.Index.NOT_ANALYZED)); > d.add(new Field("Cust",q3,Field.Store.NO,Field.Index.NOT_ANALYZED)); > > try { > writer.addDocument(d); > writer.close(); > endTime = System.currentTimeMillis(); > //System.out.println("Time taken to index the contract with > DocID "+q1 +" is -> " +(endTime-startTime)); > } > > catch (IOException e1) { > e1.printStackTrace(); > } > > > Searching Code : > > File indexDir = new File("index-dir"); > KeywordAnalyzer analyzer = new KeywordAnalyzer(); > IndexSearcher searcher = null; > > searcher = new IndexSearcher(FSDirectory.open(indexDir)); > > > String[] fields = new String[] { "DocId","Item","Cust","All"}; > MultiFieldQueryParser parser = new > MultiFieldQueryParser(Version.LUCENE_31,fields,analyzer); > parser.setAllowLeadingWildcard(true); > > String queryString = field.getValue().toString(); > TopDocs results = null; > > > Query query1; > query1 = parser.parse(queryString); > results = searcher.search(query1,1000); > > > System.out.println("total hits: " + results.totalHits); > ScoreDoc[] hits = results.scoreDocs; > Document doc = null; > ArrayList docIds = new ArrayList(); > for (ScoreDoc hit : hits) > { > doc = searcher.doc(hit.doc); > System.out.println(doc.get("DocId")); > > ((ArrayList) docIds).add(doc.get("DocId")); > > } > // Function which you need not to understand > IMnCriterion criterion = > contractQuery.createInCriterion(contractQuery.ATTR_P_DOC_ID, docIds); > contractQuery.setCriterion(criterion); > searcher.close(); > } > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org