Skip to content

Commit

Permalink
Merge pull request #534 from wcmc-its/Enclose-email-in-quotes
Browse files Browse the repository at this point in the history
Update EmailRetrievalStrategy.java
  • Loading branch information
paulalbert1 authored Oct 15, 2024
2 parents dd525c3 + 5fe2878 commit 6a23e64
Showing 1 changed file with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,38 @@ public String getRetrievalStrategyName() {
/**
* Concatenate email strings with " or ".
*/

private String constructEmailQuery(Identity identity) {
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) {

// Below is code from Apache's StringUtils class, modified to remove null checks.
Iterator<String> iterator = identity.getEmails().iterator();

final String first = iterator.next().replace(',', '.');
if (!iterator.hasNext()) {
return first;
}

// two or more elements
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings.
if (first != null) {
buf.append(first);
}

while (iterator.hasNext()) {
buf.append(" OR ");
final String obj = iterator.next();

// data cleaning: sometimes emails would have ',' instead of '.'
// i.e. ([email protected],edu)
// replace ',' with '.'
buf.append(obj.replace(',', '.'));
}
return buf.toString();
} else {
return null;
}
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) {

// Initialize the iterator for the email set
Iterator<String> iterator = identity.getEmails().iterator();

// Enclose the first email in double quotes
final String first = "\"" + iterator.next().replace(',', '.') + "\"";
if (!iterator.hasNext()) {
return first;
}

// For multiple emails, build the query string with double quotes
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings.
buf.append(first);

while (iterator.hasNext()) {
buf.append(" OR ");
final String obj = iterator.next();

// Replace any commas with dots and enclose in double quotes
buf.append("\"" + obj.replace(',', '.') + "\"");
}
return buf.toString();
} else {
return null;
}
}



@Override
protected List<PubMedQueryType> buildQuery(Identity identity, Map<IdentityNameType, Set<AuthorName>> identityNames) {
List<PubMedQueryType> pubMedQueries = new ArrayList<PubMedQueryType>();
Expand Down

0 comments on commit 6a23e64

Please sign in to comment.