Greetings, Problem: Update index. This code works with lucene-1.2 however throws io.Exception 'Lock time out ' with the lucene-1.3-final version. Any ideas what I might be missing? Thank you, -- [SA]
Steps taken to update the index. (i) Open the reader, find the Document with the given term and delete the term. (ii) Open Writer and the new term. <code> public synchronized void updateProductIndex(String[] keys) throws Exception { ContentFactory contentFactory = getFactory("ml.product"); ProductDocumentBuilder documentBuilder = (ProductDocumentBuilder) getBuilder("ml.product"); final String keysToString = "[ " + StringUtils.join(keys, " , ") + " ]"; logger.info("index() rebuilding for " + keysToString); logger.info(" loaded data, indexing"); long start = System.currentTimeMillis(); Iterator items = contentFactory.contentIterate(keys); // Open the deploy directory to check it contains a document for the product. IndexReader reader = IndexReader.open(deployDir); List documentsList = new ArrayList(); while (items.hasNext()) { SearchProduct product = (SearchProduct) items.next(); TermDocs terms = reader.termDocs(new Term(DocBuilderConsts.PRODUCT_ID, product.getPK().toString())); // find the documents for the given product ID delete it and then add it to the index. // There should only be one document per product in the index. if (terms.next()) { logger.info("indexProducts() removing product:" + product.getPK().toString()); try { reader.delete(terms.doc()); } catch (IOException e) { logger.error("Failed to delete product:" + product.getPK().toString(), e); throw new Exception("Failed to delete product:" + product.getPK().toString() + e.toString()); } } // write and reader cannot be open at the same time! so add the document to a temp list; documentsList.add(documentBuilder.getDocument(product)); } // make sure to close the reader. Can't have the reader and writer onen on the same index concurrently! //close this IndexReader, to flush deletions reader.close(); reader =null; if (documentsList.size() > 0) { /*create the indexer make to sure to pass param 'create' as false; don NOT want to create a new index replacing the existing index!*/ IndexWriter writer = new IndexWriter(deployDir, new StandardAnalyzer(), false); writer.mergeFactor = mergeFactor; for (int i = 0, j = documentsList.size(); i < j; i++) { Document document = (Document) documentsList.get(i); writer.addDocument(document); } writer.optimize(); writer.close(); writer =null; } logger.info(" indexer took " + (System.currentTimeMillis() - start) + " (ms) " + " to rebuild products with ids = " + keysToString); contentFactory.flush(); } </code> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]