Changeset 32441


Ignore:
Timestamp:
2018-09-13T01:37:27+12:00 (6 years ago)
Author:
Georgiy Litvinov
Message:

Added create_shortname method to Solr as inherited method creates duplicate index field names (needed in case of using more than one analyzer on one field)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/perllib/solrbuildproc.pm

    r32098 r32441  
    202202   
    203203}
     204sub create_shortname {
     205    my $self = shift(@_);
     206
     207    my ($realname) = @_;
     208    my @realnamelist = split(",", $realname);
     209    map {$_=~ s/^[a-zA-Z]+\.//;} @realnamelist; #remove namespaces
     210    my ($singlename) = $realnamelist[0];
     211
     212    # try our predefined static mapping
     213    my $name;
     214    # we can't use the quick map, so join all fields back together (without namespaces), and try sets of two characters.
     215    $realname = join ("", @realnamelist);
     216    #try the first two chars
     217    my $shortname;
     218    if ($realname =~ /^[^\w]*(\w)[^\w]*(\w)/) {
     219        $shortname = "$1$2";
     220    } else {
     221        # there aren't two letdig's in the field - try arbitrary combinations
     222        $realname = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     223        $shortname = "AB";
     224    }
     225    $shortname =~ tr/a-z/A-Z/;
     226
     227    #if already used, take the first and third letdigs and so on
     228    my $count = 1;
     229    while (defined $self->{'indexfieldmap'}->{$shortname}) {
     230        if ($realname =~ /^[^\w]*(\w)([^\w]*\w){$count}[^\w]*(\w)/) {
     231            $shortname = "$1$3";
     232            $count++;
     233            $shortname =~ tr/a-z/A-Z/;
     234
     235        }
     236        else {
     237            #remove up to and incl the first letdig
     238            $realname =~ s/^[^\w]*\w//;
     239            $count = 0;
     240        }
     241    }
     242
     243    return $shortname ;
     244}
     245
    204246
    205247sub index_field_mapping {
Note: See TracChangeset for help on using the changeset viewer.