Hi all, I've a problem about using IndexWriter#deleteDocuments to delete more then one document at once. the following is my code: Try 1: StringBuffer query_values = new StringBuffer(); query_values.append(UNIQUEID_FIELD_NAME); query_values.append(":("); boolean started = false; for(int i=0; i<uniqueIds.length; i++) { if(started) query_values.append(" OR "); else started = true; query_values.append("\""); query_values.append(uniqueIds[i]); query_values.append("\""); } query_values.append(")"); Query query = new QueryParser(UNIQUEID_FIELD_NAME, new StandardAnalyzer()).parse(query_values.toString()); IdxWriter.deleteDocuments(query); The Result of Try 1: fail, one document has be deleted
Try 2: Query[] querys = new Query[uniqueIds.length]; QueryParser qp = new QueryParser(UNIQUEID_FIELD_NAME, new KeywordAnalyzer()); for(int i=0; i<querys.length; i++) { String queryStr = UNIQUEID_FIELD_NAME + ":(\"" + uniqueIds[i] + "\")"; querys[i] = qp.parse(queryStr); } IdxWriter.deleteDocuments(querys); The result of Try 2: fail, one document has be deleted. Try 3: for(int i=0; i<uniqueIds.length; i++) { Term terms = new Term(UNIQUEID_FIELD_NAME, uniqueIds[i]); IdxWriter.deleteDocuments(terms); } The result of Try 3: its work, I can delete all of the document. Try 4: Term[] terms = new Term[uniqueIds.length]; for(int i=0; i<terms.length; i++) { terms[i] = new Term(UNIQUEID_FIELD_NAME, uniqueIds[i]); } IdxWriter.deleteDocuments(terms); The result of Try 4: if the uniqueId with more then it will be fail, no document has be deleted, but if the uniqueId just with one, and the document of this id will be delete by this way! Why? and What is wrong in my code? how can I delete multiple documents with IndexWriter#deleteDocuments ? Bon -- View this message in context: http://www.nabble.com/Why-it-doesn%27t-work-about-IndexWriter-deleteDocuments-tp25693460p25693460.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org