@@ -51,38 +51,38 @@ public String getRetrievalStrategyName() {
51
51
/**
52
52
* Concatenate email strings with " or ".
53
53
*/
54
+
54
55
private String constructEmailQuery (Identity identity ) {
55
- if (identity .getEmails () != null && !identity .getEmails ().isEmpty ()) {
56
-
57
- // Below is code from Apache's StringUtils class, modified to remove null checks.
58
- Iterator <String > iterator = identity .getEmails ().iterator ();
59
-
60
- final String first = iterator .next ().replace (',' , '.' );
61
- if (!iterator .hasNext ()) {
62
- return first ;
63
- }
64
-
65
- // two or more elements
66
- final StringBuilder buf = new StringBuilder (30 ); // 30 is approx length of 2 email strings.
67
- if (first != null ) {
68
- buf .append (first );
69
- }
70
-
71
- while (iterator .hasNext ()) {
72
- buf .append (" OR " );
73
- final String obj = iterator .next ();
74
-
75
- // data cleaning: sometimes emails would have ',' instead of '.'
76
-
77
- // replace ',' with '.'
78
- buf .append (obj .replace (',' , '.' ));
79
- }
80
- return buf .toString ();
81
- } else {
82
- return null ;
83
- }
56
+ if (identity .getEmails () != null && !identity .getEmails ().isEmpty ()) {
57
+
58
+ // Initialize the iterator for the email set
59
+ Iterator <String > iterator = identity .getEmails ().iterator ();
60
+
61
+ // Enclose the first email in double quotes
62
+ final String first = "\" " + iterator .next ().replace (',' , '.' ) + "\" " ;
63
+ if (!iterator .hasNext ()) {
64
+ return first ;
65
+ }
66
+
67
+ // For multiple emails, build the query string with double quotes
68
+ final StringBuilder buf = new StringBuilder (30 ); // 30 is approx length of 2 email strings.
69
+ buf .append (first );
70
+
71
+ while (iterator .hasNext ()) {
72
+ buf .append (" OR " );
73
+ final String obj = iterator .next ();
74
+
75
+ // Replace any commas with dots and enclose in double quotes
76
+ buf .append ("\" " + obj .replace (',' , '.' ) + "\" " );
77
+ }
78
+ return buf .toString ();
79
+ } else {
80
+ return null ;
81
+ }
84
82
}
85
83
84
+
85
+
86
86
@ Override
87
87
protected List <PubMedQueryType > buildQuery (Identity identity , Map <IdentityNameType , Set <AuthorName >> identityNames ) {
88
88
List <PubMedQueryType > pubMedQueries = new ArrayList <PubMedQueryType >();
0 commit comments