/** * Adds sets of used meta data to the index. */ private void addMetadataToIndex() { // new document for fields Document doc = new Document(); doc.add(new Field(LASTDOCUMENT, "true", StringField.TYPE_NOT_STORED )); // Attribute fields about the last document were initially not stored. However, this is not good for Lucene 6, // because it complaints that a field name having both docs where it is stored and not stored cannot be used to // build certain searches (https://goo.gl/Ee1sfm) // for (String name : listOfConceptAttrNames) doc.add(new Field(CONATTRIBUTE_FIELD + DELIM + name, name, FIELD_TYPE_STORED_INDEXED_VECT_STORE )); for (String name : listOfRelationAttrNames) doc.add(new Field(RELATTRIBUTE_FIELD + DELIM + name, name, FIELD_TYPE_STORED_INDEXED_VECT_STORE )); for (String elementOf : listOfConceptAccDataSources) doc.add(new Field(CONACC_FIELD + DELIM + elementOf, elementOf, StoredField.TYPE )); // add last document try { iw.addDocument(doc); } catch (CorruptIndexException cie) { fireEventOccurred(new DataFileErrorEvent(cie.getMessage(), "[LuceneEnv - addMetadataToIndex]")); } catch (IOException ioe) { fireEventOccurred(new DataFileErrorEvent(ioe.getMessage(), "[LuceneEnv - addMetadataToIndex]")); } }
TranslationUnitIterator() { try { ir = openIndexReader(); } catch (CorruptIndexException cie) { throw new OkapiIOException(cie.getMessage(), cie); } catch (IOException ioe) { throw new OkapiIOException(ioe.getMessage(), ioe); } currentIndex = 0; maxIndex = ir.maxDoc(); }
logger.error(e.getMessage()); e.printStackTrace();
public TranslationUnit next() { TranslationUnit tu = null; if (hasNext()) { try { // Using createTranslationUnit(), not // createTranslationUnit() // ensure that we get the inline codes tu = createTranslationUnit(ir.document(currentIndex++)); } catch (CorruptIndexException cie) { throw new OkapiIOException(cie.getMessage(), cie); } catch (IOException ioe) { throw new OkapiIOException(ioe.getMessage(), ioe); } } return tu; }
writer.close(); } catch (CorruptIndexException ex) { logger.error(ex.getMessage(), ex); } catch (IOException ex) { logger.error(ex.getMessage(), ex);
/** * Close a potentially open index. */ public void closeIndex() { try { // check if index open for writing if ( !indexWriterIsOpen ) return; // add last document to index addMetadataToIndex (); iw.prepareCommit (); iw.commit (); iw.close (); indexWriterIsOpen = false; } catch (CorruptIndexException cie) { fireEventOccurred ( new DataFileErrorEvent ( cie.getMessage(), "[LucenceEnv - closeIndex]" ) ); } catch (IOException ioe) { fireEventOccurred ( new DataFileErrorEvent ( ioe.getMessage(), "[LucenceEnv - closeIndex]" ) ); } }
fireEventOccurred ( new DataFileErrorEvent ( cie.getMessage (), "[LuceneEnv - addConceptToIndex]" ) );
error(e.getMessage()); logger.error("Search failed", e); } catch (IOException e) {