LilyResultToSolrMapper implements LResultToSolrMapper,Configurable { @Override public void map(Result result, SolrUpdateWriter solrUpdateWriter) { try { Record record = recordDecoder.decodeRecord(result); RecordEvent event = new RecordEvent(result.getFamilyMap(LilyHBaseSchema.RecordCf.DATA.bytes) .get(LilyHBaseSchema.RecordColumn.PAYLOAD.bytes), idGenerator); String tableName = event.getTableName(); LTable table = repository.getTable(tableName != null ? tableName : LilyHBaseSchema.Table.RECORD.name); if (event.getType().equals(INDEX)) { if (log.isDebugEnabled()) { log.debug(String.format("Record %1$s: reindex requested for these vtags: %2$s", record.getId(), vtagSetToNameString(event.getVtagsToIndex()))); } RecordEventHelper eventHelper = new RecordEventHelper(event, null, repository.getTypeManager()); VTaggedRecord vtRecord = new VTaggedRecord(record.getId(), eventHelper, table, repository); IndexCase indexCase = lilyIndexerConf.getIndexCase(table.getTableName(), vtRecord.getRecord()); Set<SchemaId> vtagsToIndex = event.getVtagsToIndex(); if (indexCase == null) { return; } vtagsToIndex.retainAll(indexCase.getVersionTags()); vtagsToIndex.retainAll(vtRecord.getVTags().keySet()); log.debug(vtagsToIndex.toString()); index(table, vtRecord, vtagsToIndex, solrUpdateWriter); } else if (event.getType().equals(DELETE)) { solrUpdateWriter.deleteByQuery("lily.id:" + ClientUtils.escapeQueryChars(record.getId().toString())); if (log.isDebugEnabled()) { log.debug(String.format("Record %1$s: deleted from index (if present) because of " + "delete record event", record.getId())); } if (derefMap != null) { updateDenormalizedData(repository.getRepositoryName(), event.getTableName(), record.getId(), null, null); } } else { VTaggedRecord vtRecord; Pair<Record,Record> oldAndNewRecords = IndexRecordFilterUtil.getOldAndNewRecordForRecordFilterEvaluation(record.getId(), event, repository); Record oldRecord = oldAndNewRecords.getV1(); Record newRecord = oldAndNewRecords.getV2(); IndexCase caseOld = oldRecord != null ? lilyIndexerConf.getIndexCase( event.getTableName(), oldRecord) : null; IndexCase caseNew = newRecord != null ? lilyIndexerConf.getIndexCase( event.getTableName(), newRecord) : null; if (oldRecord != null && newRecord != null) { if (caseOld != null && caseNew != null) { Set<SchemaId> droppedVtags = new HashSet<SchemaId>(caseOld.getVersionTags()); droppedVtags.removeAll(caseNew.getVersionTags()); if (droppedVtags.size() > 0) { for (SchemaId vtag : droppedVtags) { solrUpdateWriter.deleteById(LilyResultToSolrMapper.getIndexId(tableName, record.getId(), vtag)); } } } } boolean doIndexing = true; if (caseNew != null) { doIndexing = caseNew.getVersionTags().size() > 0; } else if (caseNew == null && caseOld != null) { doIndexing = caseOld.getVersionTags().size() > 0; } RecordEventHelper eventHelper = new RecordEventHelper(event, null, repository.getTypeManager()); if (doIndexing) { try { vtRecord = new VTaggedRecord(record.getId(), eventHelper, repository.getTable(event.getTableName()), repository); } catch (RecordNotFoundException e) { return; } handleRecordCreateUpdate(vtRecord, table, solrUpdateWriter); } if (derefMap != null) { updateDenormalizedData(repository.getRepositoryName(), event.getTableName(), record.getId(), eventHelper.getUpdatedFieldsByScope(), eventHelper.getModifiedVTags()); } } } catch (Exception e) { log.warn("Something went wrong while indexing", e); } } LilyResultToSolrMapper(String indexName, LilyIndexerConf lilyIndexerConf, RepositoryManager repositoryManager, ZooKeeperItf zooKeeperItf); @Override void configure(Map<String, String> params); void stop(); @Override boolean containsRequiredData(Result result); @Override boolean isRelevantKV(final KeyValue kv); @Override Get getGet(byte[] row); @Override void map(Result result, SolrUpdateWriter solrUpdateWriter); @Override LRepository getRepository();  }
@Test public void testMap() throws Exception { IdGenerator idGenerator = new IdGeneratorImpl(); System.out.println(Bytes.toString(idGenerator.fromString("USER.batch-index-custom").toBytes())); LTable table = repository.getDefaultTable(); Record record = table.recordBuilder() .assignNewUuid() .recordType(new QName(NS1, "rt1")) .field(new QName(NS1, "a_string"), "myvalue") .create(); Result result = encodeRecord(record); mapper.map(result, solrUpdateWriter); Assert.assertFalse(solrUpdateWriter.documents.isEmpty()); SolrInputDocument doc = solrUpdateWriter.documents.get(0); Assert.assertTrue(doc.containsKey("a_string")); Assert.assertEquals("myvalue", doc.get("a_string").getValue()); }