@@ -31,6 +31,8 @@ public class SearchData implements Serializable {
3131
3232 // set of special characters to be escaped before sending to SOLR
3333 protected static Pattern TEXT_REGEX_CHARACTERS = Pattern .compile ("[{}()\\ [\\ ].+*?^$\\ \\ |]" );
34+ // set of special characters to be escaped before sending to SOLR - allow SOLR wildcards
35+ protected static Pattern STRING_REGEX_CHARACTERS = Pattern .compile ("[{}()\\ [\\ ].+^$\\ \\ |]" );
3436 // set of special characters applying to TOKENS in SOLR
3537 protected static Pattern TOKEN_REGEX_CHARACTERS = Pattern .compile ("[{}()\\ [\\ ].+*?^$\\ \\ |\" ]" );
3638
@@ -167,11 +169,15 @@ public void setSort(String sort) {
167169 * @return the String with any special characters escaped
168170 */
169171 protected static String escape (String in ) {
172+ return escape (in , false );
173+ }
174+ protected static String escape (String in , boolean allowWildcards ) {
175+ Pattern targetPattern = allowWildcards ? STRING_REGEX_CHARACTERS : TEXT_REGEX_CHARACTERS ;
170176 return (null ==in ) ?
171177 "" :
172- TEXT_REGEX_CHARACTERS .matcher (in ).replaceAll ("\\ \\ $0" );
178+ targetPattern .matcher (in ).replaceAll ("\\ \\ $0" );
173179 }
174-
180+
175181 /**
176182 * Escape SOLR special characters in TOKEN expressions.
177183 *
@@ -196,7 +202,7 @@ public String toQ() {
196202
197203 if (!StringUtils .isEmpty (getAllFields ())) {
198204 if (q .length ()>0 ) q .append (" " );
199- q .append ("_text_:(" ).append (escape (getAllFields ())).append (")" );
205+ q .append ("_text_:(" ).append (escape (getAllFields (), true )).append (")" );
200206 }
201207 if (null !=getAccessibility ()) {
202208 StringBuilder codes = new StringBuilder ();
@@ -234,7 +240,7 @@ public String toQ() {
234240 }
235241 if (!StringUtils .isEmpty (getKeywords ())) {
236242 if (q .length ()>0 ) q .append (" " );
237- q .append ("keywords:(" ).append (escape (getKeywords ())).append (")" );
243+ q .append ("keywords:(" ).append (escape (getKeywords (), true )).append (")" );
238244 }
239245 if (null !=getProjectKeywords ()) {
240246 StringBuilder values = new StringBuilder ();
@@ -260,15 +266,15 @@ public String toQ() {
260266 }
261267 if (!StringUtils .isEmpty (getBiblioData ())) {
262268 if (q .length ()>0 ) q .append (" " );
263- q .append ("_text_:(" ).append (escape (getBiblioData ())).append (")" );
269+ q .append ("_text_:(" ).append (escape (getBiblioData (), true )).append (")" );
264270 }
265271 if (!StringUtils .isEmpty (getOrcid ())) {
266272 if (q .length ()>0 ) q .append (" " );
267273 q .append ("_orcids:(" ).append (escape (getOrcid ())).append (")" );
268274 }
269275 if (!StringUtils .isEmpty (getDevelopersContributors ())) {
270276 if (q .length ()>0 ) q .append (" " );
271- q .append ("_names:(" ).append (escape (getDevelopersContributors ())).append (")" );
277+ q .append ("_names:(" ).append (escape (getDevelopersContributors (), true )).append (")" );
272278 }
273279 if (!StringUtils .isEmpty (getIdentifiers ())) {
274280 if (q .length ()>0 ) q .append (" " );
@@ -298,7 +304,7 @@ public String toQ() {
298304 }
299305 if (!StringUtils .isEmpty (getSoftwareTitle ())) {
300306 if (q .length ()>0 ) q .append (" " );
301- q .append ("softwareTitle:(" ).append (escape (getSoftwareTitle ())).append (")" );
307+ q .append ("softwareTitle:(" ).append (escape (getSoftwareTitle (), true )).append (")" );
302308 }
303309 if (null !=getDateEarliest ()) {
304310 if (q .length ()>0 ) q .append (" " );
0 commit comments