--- trunk/vhost/webpac2.cgi 2009/04/25 10:59:43 1154 +++ trunk/vhost/webpac2.cgi 2009/04/25 11:00:22 1155 @@ -99,6 +99,23 @@ my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup +# XXX pipe delimit list! +my $select_attr_operators = << '__ATTR_OPERATORS__'; +Q* | Bilo koja riječ +BW Q | Početak +BW Q EW | Točan oblik +__ATTR_OPERATORS__ + +my $attr_operator; + +foreach ( split(/[\n\r]+/, $select_attr_operators ) ) { + my ( $operator,$label ) = split(/\s+\|\s+/,$_,2); + push @{ $attr_operator->{ '-values' } }, $operator; + $attr_operator->{ '-labels' }->{$operator} = $label; +} + +warn "## attr_operator = ", dump( $attr_operator ); + print start_html( -title => $db->{name}, @@ -113,13 +130,7 @@ # -linebreak => 0, ), textfield( -name => 'search' ), - popup_menu( -name => 'attr_operator', -values => [ '', 'STRBW', 'STREQ' ], - -labels => { - '' => 'Bilo koja riječ', - 'STRBW' => 'Početak', - 'STREQ' => 'Točan oblik', - }, - ), + popup_menu( -name => 'attr_operator', %$attr_operator ), submit, hidden( -name => 'entries_per_page', -default => $entries_per_page ), hidden( -name => 'current_page', -default => 1 ), @@ -154,32 +165,55 @@ dump_yaml( 'pager', $pager ); - my @search = ( "xml=$search" ); + my @search = (); -# if ( my $op = param('attr_operator') ) { -# $cond->add_attr( param('attr') . " $op " . param('search') ); -# } + if ( $search =~ m{(=|"|AND|OR)} ) { + push @search, $search; + } elsif ( my $op = param('attr_operator') ) { + my $attr = param('attr'); + my $v = $search; + $v =~ s/^\s+//; + warn "-- v: $v\n"; + sub rewrite { + my ( $whitespace, $v ) = @_; + warn "## filter $op $whitespace $v\n"; + my $template = $op; + $template =~ s{Q}{$v}; + $whitespace = " AND " if $whitespace; + + return + $whitespace . + $attr . '="' . $template . '"'; + ; + }; + $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge; + + push @search, $v; + } else { + push @search, "xml=$search"; + } my @only_input = param('only_input'); push @search, '(' . join(') or (', @only_input) . ')' if @only_input; my $q = '(' . join(') and (', @search) . ')'; + $q =~ s{\(\((.+)\)\)}{($1)}; warn "# query: $q\n"; my $swish_results = $swish->query( $q ); - $swish->abort_last_error if $swish->Error; dump_yaml( 'swish_results', $swish_results ); $pager->total_entries( $swish_results->hits ); if ( ! $pager->total_entries ) { - my $no_results = "No results for search '%s'"; - printf qq|
$no_results
\n\n|, $search; + my $no_results = 'No results for search %s'; + $no_results = $swish->error_string . '
%s' if $swish->error; + printf qq|
$no_results
\n\n|, $q; } else { my $results = "%d results for search %s showing results %d - %d"; - printf qq|
$results
\n\n|, $pager->total_entries, $search, $pager->first, $pager->last; + printf qq|
$results
\n\n|, $pager->total_entries, $q, $pager->first, $pager->last; my $pager_html = join("\n", show_pager( $pager ));