Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FUS-2536: Sent the same document twice - testing #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class RandomContentFetcher implements ContentFetcher {
private static final String CONTENT_ID = "content-example";
private static final String ERROR_ID = "no-number-this-should-fail";
private static final String COUNTER_FIELD = "number";
private static final String DOCUMENT_ID = "document-direct-example";

private final RandomContentGenerator generator;
private final RandomContentProperties randomContentProperties;
Expand Down Expand Up @@ -60,9 +61,13 @@ public FetchResult fetch(FetchContext fetchContext) {
fetchContext.newCandidate(ERROR_ID).emit();
// Emits an item indicating that will produce a Content Item
fetchContext.newCandidate(CONTENT_ID).emit();

logger.info("Send the same document twice {}", DOCUMENT_ID);
emitDocumentDirect(fetchContext);
emitDocumentDirect(fetchContext);

return fetchContext.newResult();
}

if (CONTENT_ID.equals(fetchContext.getFetchInput().getId())) {
emitContent(fetchContext, input);
} else {
Expand Down Expand Up @@ -109,6 +114,26 @@ private void emitDocument(FetchContext fetchContext, FetchInput input) {
}
}

private void emitDocumentDirect(FetchContext fetchContext) {
logger.info("Emitting Document without candidate -> {}", DOCUMENT_ID);

int min = randomContentProperties.minimumNumberSentences();
int max = randomContentProperties.maximumNumberSentences();

String headline = generator.makeHeadline();
String txt = generator.makeRandomText(min, max);
fetchContext.newDocument(DOCUMENT_ID)
.fields(f -> {
f.setLong("timestamp", Instant.now().toEpochMilli());
f.setString("hostname", hostname);
f.setString("headline", headline);
f.setString("text", txt);
f.setLocalDateTime("crawl_date", LocalDateTime.now());
})
.emit();

}

private void emitContent(FetchContext fetchContext, FetchInput input) {
logger.info("Emitting content of input={}", input);
// For Example purpose - the connector is getting a file from the resources folder and emit it as a Content.
Expand Down