Skip to content

Instantly share code, notes, and snippets.

@mezzatto
Created August 24, 2016 14:43
Show Gist options
  • Save mezzatto/1ce2f5b388a21016b19d4c854538f66c to your computer and use it in GitHub Desktop.
Save mezzatto/1ce2f5b388a21016b19d4c854538f66c to your computer and use it in GitHub Desktop.
Tracking Update
public class TrackingUpdateRequestProcessor extends UpdateRequestProcessor {
private final SchemaField sf;
public static ConcurrentHashMap<BytesRef, Long> changes = new ConcurrentHashMap<>();
public TrackingUpdateRequestProcessor(SolrQueryRequest req, UpdateRequestProcessor next) {
super(next);
sf = req.getCore().getLatestSchema().getUniqueKeyField();
}
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
BytesRefBuilder b = new BytesRefBuilder();
sf.getType().readableToIndexed(cmd.getSolrInputDocument().getFieldValue("id").toString(), b);
changes.put(b.get(), 1L);
super.processAdd(cmd);
}
@Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
changes.put(cmd.getIndexedId(), 0L);
super.processDelete(cmd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment