public static void recoverSrcData( SenseiResult res, SenseiHit[] hits, boolean isFetchStoredFields) { if (hits != null) { for (SenseiHit hit : hits) { try { byte[] dataBytes = hit.getStoredValue(); if (dataBytes == null || dataBytes.length == 0) { dataBytes = hit.getFieldBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); } if (dataBytes != null && dataBytes.length > 0) { byte[] data = null; try { // TODO need check SenseiSchema.isCompressSrcData() data = DefaultJsonSchemaInterpreter.decompress(dataBytes); } catch (Exception ex) { data = dataBytes; } hit.setSrcData(new String(data, "UTF-8")); } } catch (Exception e) { logger.error(e.getMessage(), e); res.getErrors().add(new SenseiError(e.getMessage(), ErrorType.BrokerGatherError)); } recoverSrcData(res, hit.getSenseiGroupHits(), isFetchStoredFields); // Remove stored fields since the user is not requesting: if (!isFetchStoredFields) { hit.setStoredFields((List<SerializableField>) null); } } } }
public static void recoverSrcData( SenseiResult res, SenseiHit[] hits, boolean isFetchStoredFields) { if (hits != null) { for (SenseiHit hit : hits) { try { byte[] dataBytes = hit.getStoredValue(); if (dataBytes == null || dataBytes.length == 0) { Document doc = hit.getStoredFields(); if (doc != null) { dataBytes = doc.getBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); if (dataBytes == null || dataBytes.length == 0) { dataBytes = doc.getBinaryValue(SenseiSchema.SRC_DATA_COMPRESSED_FIELD_NAME); if (dataBytes == null || dataBytes.length == 0) { dataBytes = doc.getBinaryValue(SenseiSchema.SRC_DATA_FIELD_NAME); if (dataBytes != null && dataBytes.length > 0) { hit.setSrcData(new String(dataBytes, "UTF-8")); dataBytes = null; // set to null to avoid gunzip. } } doc.removeFields(SenseiSchema.SRC_DATA_COMPRESSED_FIELD_NAME); doc.removeFields(SenseiSchema.SRC_DATA_FIELD_NAME); } } } if (dataBytes != null && dataBytes.length > 0) { byte[] data; try { data = DefaultJsonSchemaInterpreter.decompress(dataBytes); } catch (Exception ex) { data = dataBytes; } hit.setSrcData(new String(data, "UTF-8")); } } catch (Exception e) { logger.error(e.getMessage(), e); res.getErrors().add(new SenseiError(e.getMessage(), ErrorType.BrokerGatherError)); } recoverSrcData(res, hit.getSenseiGroupHits(), isFetchStoredFields); // Remove stored fields since the user is not requesting: if (!isFetchStoredFields) hit.setStoredFields(null); } } }