commit b652d818053bc912937743b018f352b45f68b21f
Author: Dobrica Pavlinusic <dpavlin@rot13.org>
Date:   Tue Jul 9 14:17:40 2013 +0200

    backport fix from next eprints version

diff --git a/EPrints/MetaField/Name.pm b/EPrints/MetaField/Name.pm
index 4ca4db2..88f42e2 100644
--- a/EPrints/MetaField/Name.pm
+++ b/EPrints/MetaField/Name.pm
@@ -210,6 +210,9 @@ sub get_search_conditions
 		$indexmode = "index_start";
 	}
 
+	# split up initials
+	$v2 = normalise_initials($v2);
+
 	# name searches are case sensitive
 	$v2 = "\L$v2";
 
@@ -223,11 +226,8 @@ sub get_search_conditions
 	}
 
 
-	# split up initials
-	$v2 =~ s/([A-Z])/ $1/g;
-
-	# remove not a-z characters (except ,)
-	$v2 =~ s/[^a-z,]/ /ig;
+	# remove not a-z characters (except , and ')
+	$v2 =~ s/[^\p{Lowercase},']/ /ig;
 
 	my( $family, $given ) = split /\s*,\s*/, $v2;
 	my @freetexts = ();
@@ -421,6 +421,17 @@ Q
 
 END
 
+sub normalise_initials
+{
+	my ($str) = @_;
+
+	# Separate upto 3 capitalised initials
+	# JR Tolkein => J R Tolkein
+	# WORDSWORTH => WORDSWORTH
+	$str =~ s/\b(\p{Uppercase}{2,3})\b/join ' ', split '', $1/eg;
+
+	return $str;
+}
 
 sub get_index_codes_basic
 {
@@ -431,11 +442,7 @@ sub get_index_codes_basic
 	my $f = &EPrints::Index::apply_mapping( $session, $value->{family} );
 	my $g = &EPrints::Index::apply_mapping( $session, $value->{given} );
 
-	# Add a space before all capitals to break
-	# up initials. Will screw up names with capital
-	# letters in the middle of words. But that's
-	# pretty rare.
-	$g =~ s/([[:upper:]])/ $1/g;
+	$g = normalise_initials($g);
 
 	my $code = '';
 	my @r = ();
