Changeset 33371


Ignore:
Timestamp:
2019-07-29T12:08:14+12:00 (2 years ago)
Author:
kjdon
Message:

separate sort and facet fields as the former needs to be single valued and the latter multi valued. also created get_or create_facetfield_shortname(), and actualfacetfields, facetfieldnamemap, to match what was done for sortfield shortnames. so we don't get duplicates of shortnames

File:
1 edited

Legend:

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

    r33327 r33371  
    5555    my $self = new lucenebuildproc (@_);
    5656
     57    $self->{'actualfacetfields'} = {};
     58    $self->{'facetfieldnamemap'} = {};
    5759    return bless $self, $class;
    5860}
     
    149151
    150152        if (!defined $self->{'indexfieldmap'}->{$real_field}) {
    151         my $shortname = $self->create_shortname($real_field);
     153        my $shortname = $self->get_or_create_shortname($real_field);
    152154        $self->{'indexfieldmap'}->{$real_field} = $shortname;
    153155        $self->{'indexfieldmap'}->{$shortname} = 1;
     
    179181        }
    180182        else {
    181             $shortname = $self->create_shortname($mfield);
     183            $shortname = $self->get_or_create_shortname($mfield);
    182184            $self->{'indexfieldmap'}->{$mfield} = $shortname;
    183185            $self->{'indexfieldmap'}->{$shortname} = 1;
     
    468470        }
    469471        else {
    470         $shortname = $self->create_shortname($real_field);
     472        $shortname = $self->get_or_create_shortname($real_field);
    471473        $new_field = 1;
    472474        }
     
    596598        }
    597599        else {
    598             $shortname = $self->create_shortname($mfield);
     600            $shortname = $self->get_or_create_shortname($mfield);
    599601            $self->{'indexfieldmap'}->{$mfield} = $shortname;
    600602            $self->{'indexfieldmap'}->{$shortname} = 1;
     
    646648    }
    647649       
    648     # only add sort fields for this section if we are indexing this section, we are doing section level indexing or this is the top section
     650    # only add sort and facet fields for this section if we are indexing this section, we are doing section level indexing or this is the top section
    649651    if ($self->{'indexing_text'} && ($sec_tag_name ne "" || $doc_section == 1 )) {
    650652    # add sort fields if there are any
    651         my $seenfields = {};
    652     foreach my $sfield (@{$self->{'sortfields'}}, @{$self->{'facetfields'}}) {
     653    foreach my $sfield (@{$self->{'sortfields'}}) {
    653654        # ignore special field rank/none
    654655        next if $sfield eq "rank" || $sfield eq "none";
    655         # ignore any we have already done - we may have duplicates in the sort and facet lists
    656         next if (defined $seenfields->{$sfield});
    657         $seenfields->{$sfield} = 1;
    658         my $sf_shortname;
    659         if (defined $self->{'sortfieldnamemap'}->{$sfield}) {
    660         $sf_shortname = $self->{'sortfieldnamemap'}->{$sfield};
    661         }
    662         else {
    663         $sf_shortname = $self->create_sortfield_shortname($sfield);
    664         $self->{'sortfieldnamemap'}->{$sfield} = $sf_shortname;
    665         $self->{'sortfieldnamemap'}->{$sf_shortname} = 1;
    666         }
     656        my $sf_shortname = $self->get_or_create_sortfield_shortname($sfield);
    667657        my @metadata_list = (); # put any metadata values in here
    668658        foreach my $submeta (split /,/, $sfield) {
     
    677667        push (@metadata_list, @section_metadata);
    678668        }
    679         # my $new_text = "";
    680         # foreach my $item (@metadata_list) {
    681         #   &ghtml::htmlsafe($item);
    682         #   $new_text .= "$item ";
    683         # }
    684         # if ($new_text =~ /\S/) {
    685         #   $new_text = "<field name=\"$sf_shortname\">$new_text</field>\n";
    686         #   # filter the text???
    687         #   $text .= "$new_text"; # add it to the main text block
    688         #   print "#### new_text: $new_text\n";
    689 
    690         #   $self->{'actualsortfields'}->{$sfield} = 1;
    691         # }
    692         # print "#### TEXT: $text\n";
    693 
     669         my $new_text = "";
    694670        foreach my $item (@metadata_list) {
    695             &ghtml::htmlsafe($item);
    696             if ($item =~ /\S/) {
    697                 $item = "<field name=\"$sf_shortname\">$item</field>\n";
    698                 # filter the text???
    699                 $text .= "$item"; # add it to the main text block
    700                 #print "#### new_text: $item\n";
    701             }
    702         }
    703         if(scalar @metadata_list > 0) {
    704             $self->{'actualsortfields'}->{$sfield} = 1;
    705         }
    706        
    707     }
    708     }
     671            &ghtml::htmlsafe($item);
     672            $new_text .= "$item ";
     673        }
     674        if ($new_text =~ /\S/) {
     675            $new_text = "<field name=\"$sf_shortname\">$new_text</field>\n";
     676            # filter the text???
     677            $text .= "$new_text"; # add it to the main text block
     678            #print "#### new_text: $new_text\n";
     679
     680            $self->{'actualsortfields'}->{$sfield} = 1;
     681        }
     682       # print "#### TEXT: $text\n";
     683       
     684
     685    }# end add in sort fields
     686
     687    # add facet fields if there are any
     688    foreach my $sfield (@{$self->{'facetfields'}}) {
     689        my $sf_shortname = $self->get_or_create_facetfield_shortname($sfield);
     690        my @metadata_list = (); # put any metadata values in here
     691        foreach my $submeta (split /,/, $sfield) {
     692        $submeta =~ s/^ex\.([^.]+)$/$1/; #strip off ex. iff it's the only metadata set prefix (will leave ex.dc.* intact)
     693       
     694        my @section_metadata = @{$doc_obj->get_metadata ($section, $submeta)};
     695            if ($section ne $doc_obj->get_top_section() && defined ($self->{'sections_sort_on_document_metadata'})) {
     696            if ($self->{'sections_sort_on_document_metadata'} eq "always" || ( scalar(@section_metadata) == 0 && $self->{'sections_sort_on_document_metadata'} eq "unless_section_metadata_exists")) {
     697                push (@section_metadata, @{$doc_obj->get_metadata ($doc_obj->get_top_section(), $submeta)});
     698            }
     699            }
     700        push (@metadata_list, @section_metadata);
     701        }
     702        my $found_facet_value = 0;
     703        foreach my $item (@metadata_list) {
     704        &ghtml::htmlsafe($item);
     705        if ($item =~ /\S/) {
     706            $item = "<field name=\"$sf_shortname\">$item</field>\n";
     707            # filter the text???
     708            $text .= "$item"; # add it to the main text block
     709            $found_facet_value = 1;
     710            #print "#### new_text: $item\n";
     711        }
     712        }
     713        if($found_facet_value) {
     714            $self->{'actualfacetfields'}->{$sfield} = 1;
     715        }
     716       
     717    }
     718    } # end add in facet fields
    709719
    710720    # add in end tag if at top-level doc root, or indexing at the section level
     
    746756}
    747757
     758sub get_or_create_facetfield_shortname {
     759    my $self = shift(@_);
     760
     761    my ($realname) = @_;
     762   
     763    if (defined $self->{'facetfieldnamemap'}->{$realname}) {
     764    return $self->{'facetfieldnamemap'}->{$realname};
     765    }
     766
     767    # get the shortname made for this index field
     768
     769    my $shortname = $self->get_or_create_shortname($realname);
     770    $shortname = "fc".$shortname;
     771
     772    $self->{'facetfieldnamemap'}->{$realname} = $shortname;
     773    $self->{'facetfieldnamemap'}->{$shortname} = 1;
     774    return $shortname;
     775}
     776 
     777
    748778
    7497791;
Note: See TracChangeset for help on using the changeset viewer.