Revision 793

Date:
2020/05/27 10:01:52
Author:
ahitrov
Revision Log:
Field weights

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/sphinx/lib/sphinx/Keeper.pm

     
    172 172 $limit = 0;
    173 173 $offset = 0;
    174 174 }
    175 my $weights = delete $opts{weights};
    175 176 my $return_value = delete $opts{return_value} || 'array_ref';
    176 177 my $hash_by = delete $opts{hash_by} || 'object_id';
    177 178
     
    186 187 push @orders, 'weight desc, last_edited desc';
    187 188 }
    188 189
    189 my $query = "select ".($count ? 'count(*) as cnt' : '*, weight() as weight')." from $db_table where ".join( ' and ', @wheres ).(@orders ? " order by ".join(', ', @orders) : '');
    190 my $query = "SELECT ".($count ? 'count(*) as cnt' : '*, weight() as weight')." FROM $db_table WHERE ".join( ' AND ', @wheres ).(@orders ? " ORDER BY ".join(', ', @orders) : '');
    191 if ( ref $weights eq 'HASH' ) {
    192 my @weights;
    193 foreach my $field ( keys %$weights ) {
    194 push @weights, "$field=".$weights->{$field};
    195 }
    196 if ( @weights ) {
    197 $query .= " OPTION field_weights=(".join(', ', @weights).") ";
    198 }
    199 }
    190 200 if ( $limit && $offset ) {
    191 $query .= " limit $offset, $limit ";
    201 $query .= " LIMIT $offset, $limit ";
    192 202 } elsif ( $limit ) {
    193 $query .= " limit 0, $limit ";
    203 $query .= " LIMIT 0, $limit ";
    194 204 }
    195 205 warn "SEARCH QUERY: $query\n" if $DEBUG;
    196 206 warn "SEARCH VALUES: ".Dumper( \@values ) if $DEBUG;