List of usage examples for org.apache.lucene.analysis.standard StandardAnalyzer setVersion
public void setVersion(Version v)
From source file:org.apache.ofbiz.content.search.DocumentIndexer.java
License:Apache License
@Override public void run() { IndexWriter indexWriter = null;//from w w w .j av a 2 s .c o m int uncommittedDocs = 0; while (true) { LuceneDocument ofbizDocument; try { // Execution will pause here until the queue receives a LuceneDocument for indexing ofbizDocument = documentIndexQueue.take(); } catch (InterruptedException e) { Debug.logError(e, module); if (indexWriter != null) { try { indexWriter.close(); indexWriter = null; } catch (IOException ioe) { Debug.logError(ioe, module); } } break; } Term documentIdentifier = ofbizDocument.getDocumentIdentifier(); Document document = ofbizDocument.prepareDocument(this.delegator); if (indexWriter == null) { try { StandardAnalyzer analyzer = new StandardAnalyzer(); analyzer.setVersion(SearchWorker.getLuceneVersion()); indexWriter = new IndexWriter(this.indexDirectory, new IndexWriterConfig(analyzer)); } catch (CorruptIndexException e) { Debug.logError("Corrupted lucene index: " + e.getMessage(), module); break; } catch (LockObtainFailedException e) { Debug.logError("Could not obtain Lock on lucene index " + e.getMessage(), module); // TODO: put the thread to sleep waiting for the locked to be released break; } catch (IOException e) { Debug.logError(e.getMessage(), module); break; } } try { if (document == null) { indexWriter.deleteDocuments(documentIdentifier); if (Debug.infoOn()) Debug.logInfo(getName() + ": deleted Lucene document: " + ofbizDocument, module); } else { indexWriter.updateDocument(documentIdentifier, document); if (Debug.infoOn()) Debug.logInfo(getName() + ": indexed Lucene document: " + ofbizDocument, module); } } catch (Exception e) { Debug.logError(e, getName() + ": error processing Lucene document: " + ofbizDocument, module); if (documentIndexQueue.peek() == null) { try { indexWriter.close(); indexWriter = null; } catch (IOException ioe) { Debug.logError(ioe, module); } } continue; } uncommittedDocs++; if (uncommittedDocs == UNCOMMITTED_DOC_LIMIT || documentIndexQueue.peek() == null) { // limit reached or queue empty, time to commit try { indexWriter.commit(); } catch (IOException e) { Debug.logError(e, module); } uncommittedDocs = 0; } if (documentIndexQueue.peek() == null) { try { indexWriter.close(); indexWriter = null; } catch (IOException e) { Debug.logError(e, module); } } } }