Added minimalistic info on how to use the replicator

Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/330c0667
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/330c0667
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/330c0667

Branch: refs/heads/master
Commit: 330c0667e81766e5edbfe09c17a8c39749ce7dae
Parents: cce39cc
Author: Jens Melgaard <[email protected]>
Authored: Mon Sep 4 12:59:54 2017 +0200
Committer: Shad Storhaug <[email protected]>
Committed: Sat Sep 9 06:57:17 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Replicator/Http/replicator.md | 53 ++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/330c0667/src/Lucene.Net.Replicator/Http/replicator.md
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/replicator.md 
b/src/Lucene.Net.Replicator/Http/replicator.md
index 3e055cf..0de6006 100644
--- a/src/Lucene.Net.Replicator/Http/replicator.md
+++ b/src/Lucene.Net.Replicator/Http/replicator.md
@@ -108,4 +108,55 @@ public static class AspNetCoreReplicationServiceExtentions
 
 Now the implementation can be used wihin AspNetCore in order to service Lucene 
Replicator requests over http.
 
-TODO: Finish.
\ No newline at end of file
+In order to enable replication of indexes, the IndewWriter that writes the 
index should be created with a `SnapshotDeletionPolicy`.
+
+```csharp
+IndexWriterConfig config = new IndexWriterConfig(...ver..., new 
StandardAnalyzer(...ver...));
+config.IndexDeletionPolicy = new 
SnapshotDeletionPolicy(config.IndexDeletionPolicy);
+IndexWriter writer = new IndexWriter(FSDirectory.Open("..."), config);
+```
+
+For the absolute minimal solution we can wire the ReplicatorService up on the 
server side as:
+
+```csharp
+LocalReplicator replicator = new LocalReplicator(); 
+ReplicatorService service = new ReplicationService(new Dictionary<string, 
IReplicator>{
+    ["shard_name"] = replicator
+}, "/api/replicate");
+
+app.Map("/api/replicate", builder => {
+    builder.Run(async context => {
+        await Task.Yield();
+        service.Perform(context.Request, context.Response); 
+    });
+});
+```
+
+Now in order to publish a Revision call the publish method in the 
LocalReplicator:
+
+```csharp
+IndexWriter writer = ...;
+LocalReplicator replicator = ...;
+replicator.Publish(new IndexRevision(writer));
+```
+
+On the client side create a new HttpReplicator and start replicating, e.g.:
+
+```csharp
+IReplicator replicator = new 
HttpReplicator("http://{host}:{port}/api/replicate/shard_name";);
+ReplicationClient client = new ReplicationClient(
+    replicator, 
+    new IndexReplicationHandler(
+        FSDirectory.Open(...directory...), 
+        () => ...onUpdate...), 
+        new PerSessionDirectoryFactory(...temp-working-directory...));
+
+//Now either start the Update Thread or do manual pulls periodically.
+client.UpdateNow(); //Manual Pull
+client.StartUpdateThread(1000, "Replicator Thread"); //Pull automatically 
every second if there is any changes.
+```
+
+From here it would be natural to use a SearchManager over the directory in 
order to get Searchers updated outomatically.
+But this cannot be created before the first actual replication as the 
SearchManager will fail because there is no index.
+
+We can use the onUpdate handler to perform the first initialization in this 
case.
\ No newline at end of file

Reply via email to