Skip to content

Commit 8cec4a0

Browse files
hdhayneCoveoy-lakhdar
authored andcommitted
docs: create sample code to stream document (#43)
1 parent df21493 commit 8cec4a0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

samples/StreamDocuments.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import com.coveo.pushapiclient.*;
2+
import com.coveo.pushapiclient.exceptions.NoOpenStreamException;
3+
4+
import java.io.IOException;
5+
import java.util.HashMap;
6+
7+
public class StreamDocuments {
8+
9+
public static void main(String[] args) throws IOException, InterruptedException, NoOpenStreamException {
10+
11+
PlatformUrl platformUrl = new PlatformUrlBuilder().withEnvironment(Environment.PRODUCTION).withRegion(Region.US).build();
12+
CatalogSource catalogSource = CatalogSource.fromPlatformUrl("my_api_key","my_org_id","my_source_id", platformUrl);
13+
14+
StreamService streamService = new StreamService(catalogSource);
15+
16+
DocumentBuilder document1 = new DocumentBuilder("https://my.document.uri", "My document title")
17+
.withData("these words will be searchable")
18+
.withAuthor("bob")
19+
.withClickableUri("https://my.document.click.com")
20+
.withFileExtension(".html")
21+
.withMetadata(new HashMap<>() {{
22+
put("tags", new String[]{"the_first_tag", "the_second_tag"});
23+
put("version", 1);
24+
put("somekey", "somevalue");
25+
}});
26+
27+
streamService.add(document1);
28+
29+
DocumentBuilder document2 = new DocumentBuilder("https://my.document2.uri", "My document2 title");
30+
streamService.add(document2);
31+
32+
streamService.close();
33+
}
34+
}

src/main/java/com/coveo/pushapiclient/StreamService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public StreamService(StreamEnabledSource source) {
6262
* </pre>
6363
*
6464
* <p>
65-
* For more code samples, visit <a href="TODO: LENS-840">Stream data to your catalog source</a>
65+
* For more code samples, @see `samples/StreamDocuments.java`
6666
*
6767
* @param document The documentBuilder to add to your source
6868
* @throws InterruptedException

0 commit comments

Comments
 (0)