View | Details | Raw Unified | Return to bug 12443
Collapse All | Expand All

(-)a/C4/Search.pm (-37 / +48 lines)
Lines 1486-1528 sub buildQuery { Link Here
1486
1486
1487
                warn "FIELD WEIGHTED OPERAND: >$weighted_operand<" if $DEBUG;
1487
                warn "FIELD WEIGHTED OPERAND: >$weighted_operand<" if $DEBUG;
1488
1488
1489
                # If there's a previous operand, we need to add an operator
1489
                ($query,$query_cgi,$query_desc,$previous_operand) = _build_initial_query({
1490
                if ($previous_operand) {
1490
                    query => $query,
1491
1491
                    query_cgi => $query_cgi,
1492
                    # User-specified operator
1492
                    query_desc => $query_desc,
1493
                    if ( $operators[ $i - 1 ] ) {
1493
                    operator => ($operators[ $i - 1 ]) ? $operators[ $i - 1 ] : '',
1494
                        $query     .= " $operators[$i-1] ";
1494
                    parsed_operand => $operand,
1495
                        $query     .= " $index_plus " unless $indexes_set;
1495
                    original_operand => ($operands[$i]) ? $operands[$i] : '',
1496
                        $query     .= " $operand";
1496
                    index => $index,
1497
                        $query_cgi .= "&op=".uri_escape($operators[$i-1]);
1497
                    index_plus => $index_plus,
1498
                        $query_cgi .= "&idx=".uri_escape($index) if $index;
1498
                    indexes_set => $indexes_set,
1499
                        $query_cgi .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1499
                    previous_operand => $previous_operand,
1500
                        $query_desc .=
1500
                });
1501
                          " $operators[$i-1] $index_plus $operands[$i]";
1502
                    }
1503
1504
                    # Default operator is and
1505
                    else {
1506
                        $query      .= " and ";
1507
                        $query      .= "$index_plus " unless $indexes_set;
1508
                        $query      .= "$operand";
1509
                        $query_cgi  .= "&op=and&idx=".uri_escape($index) if $index;
1510
                        $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1511
                        $query_desc .= " and $index_plus $operands[$i]";
1512
                    }
1513
                }
1514
1515
                # There isn't a pervious operand, don't need an operator
1516
                else {
1517
1501
1518
                    # Field-weighted queries already have indexes set
1519
                    $query .= " $index_plus " unless $indexes_set;
1520
                    $query .= $operand;
1521
                    $query_desc .= " $index_plus $operands[$i]";
1522
                    $query_cgi  .= "&idx=".uri_escape($index) if $index;
1523
                    $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1524
                    $previous_operand = 1;
1525
                }
1526
            }    #/if $operands
1502
            }    #/if $operands
1527
        }    # /for
1503
        }    # /for
1528
    }
1504
    }
Lines 1627-1632 sub buildQuery { Link Here
1627
    );
1603
    );
1628
}
1604
}
1629
1605
1606
=head2 _build_initial_query
1607
1608
  ($query, $query_cgi, $query_desc, $previous_operand) = _build_initial_query($initial_query_params);
1609
1610
  Build a section of the initial query containing indexes, operators, and operands.
1611
1612
=cut
1613
1614
sub _build_initial_query {
1615
    my ($params) = @_;
1616
1617
    my $operator = "";
1618
    if ($params->{previous_operand}){
1619
        #If there is a previous operand, add a supplied operator or the default 'and'
1620
        $operator = ($params->{operator}) ? " ".($params->{operator})." " : ' and ';
1621
    }
1622
1623
    #NOTE: indexes_set is typically set when doing truncation or field weighting
1624
    my $operand = ($params->{indexes_set}) ? $params->{parsed_operand} : $params->{index_plus}.$params->{parsed_operand};
1625
1626
    #e.g. "kw,wrdl:test"
1627
    #e.g. " and kw,wrdl:test"
1628
    $params->{query} .= $operator . $operand;
1629
1630
    $params->{query_cgi} .= "&op=".uri_escape($operator) if $operator;
1631
    $params->{query_cgi} .= "&idx=".uri_escape($params->{index}) if $params->{index};
1632
    $params->{query_cgi} .= "&q=".uri_escape($params->{original_operand}) if $params->{original_operand};
1633
1634
    #e.g. " and kw,wrdl: test"
1635
    $params->{query_desc} .= $operator . $params->{index_plus} . " " . $params->{original_operand};
1636
1637
    $params->{previous_operand} = 1 unless $params->{previous_operand}; #If there is no previous operand, mark this as one
1638
1639
    return ($params->{query}, $params->{query_cgi}, $params->{query_desc}, $params->{previous_operand});
1640
}
1641
1630
=head2 searchResults
1642
=head2 searchResults
1631
1643
1632
  my @search_results = searchResults($search_context, $searchdesc, $hits, 
1644
  my @search_results = searchResults($search_context, $searchdesc, $hits, 
1633
- 

Return to bug 12443