/** * Do a best effort to clean up all resources allocated when populating * a Lucene document. On normal execution, these resources should be * closed automatically by the index writer once it's done with them, but * we may not get that far if something fails. * * @param doc the document whose resources to clean up */ private static void cleanupResources(Document doc) { for (IndexableField f : doc) { // If the field takes input from a reader, close the reader. IOUtils.close(f.readerValue()); // If the field takes input from a token stream, close the // token stream. if (f instanceof Field) { IOUtils.close(((Field) f).tokenStreamValue()); } } }
@Override public Reader getReader() { return field.readerValue(); }
@Override public Reader readerValue() { return getRealValue().readerValue(); }
@Override public Reader readerValue() { return getRealValue().readerValue(); }
@Override public Reader readerValue() { return getRealValue().readerValue(); }
/** * @see org.opencms.search.I_CmsSearchDocument#getContentBlob() */ public byte[] getContentBlob() { IndexableField fieldContentBlob = m_doc.getField(CmsSearchField.FIELD_CONTENT_BLOB); if (fieldContentBlob != null) { try { if (fieldContentBlob.readerValue() != null) { return IOUtils.toByteArray(fieldContentBlob.readerValue()); } } catch (IOException e) { // TODO: } } return null; }
private Document createNewDoc(IndexReader originalIndex, FieldType ft, ScoreDoc scoreDoc, String[] fieldNames) throws IOException { Document doc = new Document(); Document document = originalIndex.document(scoreDoc.doc); if (fieldNames != null && fieldNames.length > 0) { for (String fieldName : fieldNames) { IndexableField field = document.getField(fieldName); if (field != null) { doc.add(new Field(fieldName, field.stringValue(), ft)); } } } else { for (IndexableField field : document.getFields()) { if (field.readerValue() != null) { doc.add(new Field(field.name(), field.readerValue(), ft)); } else if (field.binaryValue() != null) { doc.add(new Field(field.name(), field.binaryValue(), ft)); } else if (field.stringValue() != null) { doc.add(new Field(field.name(), field.stringValue(), ft)); } else if (field.numericValue() != null) { doc.add(new Field(field.name(), field.numericValue().toString(), ft)); } } } return doc; }