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

Indexer ES document id #1028

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -175,6 +175,17 @@ protected Map<String, String[]> filterMetadata(Metadata meta) {
return fieldVals;
}

/**
* Get the document id.
*
* @param metadata The {@link Metadata}.
* @param normalisedUrl The normalised url.
* @return Return the normalised url SHA-256 digest as String.
*/
protected String getDocumentID(Metadata metadata, String normalisedUrl) {
return org.apache.commons.codec.digest.DigestUtils.sha256Hex(normalisedUrl);
}

/**
* Returns the value to be used as the URL for indexing purposes, if present the canonical value
* is used instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public void prepare(
client.setEndpoint(endpoint);
}

@Override
protected String getDocumentID(Metadata metadata, String normalisedUrl) {
return CloudSearchUtils.getID(normalisedUrl);
}

@Override
public void execute(Tuple tuple) {

Expand Down Expand Up @@ -204,7 +209,7 @@ public void execute(Tuple tuple) {
doc_builder.put("type", "add");

// generate the id from the normalised url
String ID = CloudSearchUtils.getID(normalisedurl);
String ID = getDocumentID(metadata, normalisedurl);
doc_builder.put("id", ID);

ObjectNode fields = objectMapper.createObjectNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void execute(Tuple tuple) {
return;
}

String docID = org.apache.commons.codec.digest.DigestUtils.sha256Hex(normalisedurl);
String docID = getDocumentID(metadata, normalisedurl);

try {
XContentBuilder builder = jsonBuilder().startObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void execute(Tuple tuple) {
return;
}

final String docID = org.apache.commons.codec.digest.DigestUtils.sha256Hex(normalisedurl);
final String docID = getDocumentID(metadata, normalisedurl);

try {
final XContentBuilder builder = jsonBuilder().startObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void execute(Tuple tuple) {
// Distinguish the value used for indexing
// from the one used for the status
String normalisedurl = valueForURL(tuple);
doc.addField(fieldNameForURL(), normalisedurl);
doc.addField(fieldNameForURL(), getDocumentID(metadata, normalisedurl));
Mikwiss marked this conversation as resolved.
Show resolved Hide resolved
}

// select which metadata to index
Expand Down Expand Up @@ -133,4 +133,9 @@ public void execute(Tuple tuple) {
_collector.fail(tuple);
}
}

@Override
protected String getDocumentID(Metadata metadata, String normalisedUrl) {
return normalisedUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void execute(Tuple tuple) {

// send URL as field?
if (fieldNameForURL() != null) {
preparedStmt.setString(1, normalisedurl);
preparedStmt.setString(1, getDocumentID(metadata, normalisedurl));
Mikwiss marked this conversation as resolved.
Show resolved Hide resolved
}

for (int i = 0; i < keys.length; i++) {
Expand Down Expand Up @@ -168,6 +168,11 @@ public void execute(Tuple tuple) {
}
}

@Override
protected String getDocumentID(Metadata metadata, String normalisedUrl) {
return normalisedUrl;
}

private void insert(
PreparedStatement preparedStmt,
int position,
Expand Down