From 8c607b847faac0f2ec86c9ffc2ca553bf0387eb3 Mon Sep 17 00:00:00 2001 From: Houssein Date: Thu, 8 Jun 2023 17:09:10 -0400 Subject: [PATCH 1/2] doc: create sample code to stream document --- samples/StreamDocuments.java | 34 +++++++++++++++++++ .../coveo/pushapiclient/StreamService.java | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 samples/StreamDocuments.java diff --git a/samples/StreamDocuments.java b/samples/StreamDocuments.java new file mode 100644 index 00000000..38963c84 --- /dev/null +++ b/samples/StreamDocuments.java @@ -0,0 +1,34 @@ +import com.coveo.pushapiclient.*; +import com.coveo.pushapiclient.exceptions.NoOpenStreamException; + +import java.io.IOException; +import java.util.HashMap; + +public class StreamDocuments { + + public static void main(String[] args) throws IOException, InterruptedException, NoOpenStreamException { + + PlatformUrl platformUrl = new PlatformUrlBuilder().withEnvironment(Environment.PRODUCTION).withRegion(Region.US).build(); + CatalogSource catalogSource = CatalogSource.fromPlatformUrl("my_api_key","my_org_id","my_source_id", platformUrl); + + StreamService streamService = new StreamService(catalogSource); + + DocumentBuilder document1 = new DocumentBuilder("https://my.document.uri", "My document title") + .withData("these words will be searchable") + .withAuthor("bob") + .withClickableUri("https://my.document.click.com") + .withFileExtension(".html") + .withMetadata(new HashMap<>() {{ + put("tags", new String[]{"the_first_tag", "the_second_tag"}); + put("version", 1); + put("somekey", "somevalue"); + }}); + + streamService.add(document1); + + DocumentBuilder document2 = new DocumentBuilder("https://my.document2.uri", "My document2 title"); + streamService.add(document2); + + streamService.close(); + } +} diff --git a/src/main/java/com/coveo/pushapiclient/StreamService.java b/src/main/java/com/coveo/pushapiclient/StreamService.java index b9212e20..f830cdd8 100644 --- a/src/main/java/com/coveo/pushapiclient/StreamService.java +++ b/src/main/java/com/coveo/pushapiclient/StreamService.java @@ -65,7 +65,7 @@ public StreamService(StreamEnabledSource source) { * * *

- * For more code samples, visit Stream data to your catalog source + * For more code samples, @see StreamDocuments * * @param document The documentBuilder to add to your source * @throws InterruptedException From ba0b3149f9ed15a71a49e2e18fa065b59fbda2a5 Mon Sep 17 00:00:00 2001 From: Houssein Date: Mon, 12 Jun 2023 14:30:48 -0400 Subject: [PATCH 2/2] Apply review comments --- src/main/java/com/coveo/pushapiclient/StreamService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/coveo/pushapiclient/StreamService.java b/src/main/java/com/coveo/pushapiclient/StreamService.java index 25aad672..b583f6ce 100644 --- a/src/main/java/com/coveo/pushapiclient/StreamService.java +++ b/src/main/java/com/coveo/pushapiclient/StreamService.java @@ -62,7 +62,7 @@ public StreamService(StreamEnabledSource source) { * * *

- * For more code samples, @see StreamDocuments + * For more code samples, @see `samples/StreamDocuments.java` * * @param document The documentBuilder to add to your source * @throws InterruptedException