--- trunk/vhost/webpac2.cgi 2009/04/26 00:07:58 1174 +++ trunk/vhost/webpac2.cgi 2009/05/26 15:00:57 1192 @@ -142,13 +142,8 @@ push @style, "../../$path/$path.css" if -e "$dir/$path/$path.css"; dump_yaml( 'style', \@style ); -print - start_html( - -title => $db->{name}, - -style => [ @style ], - ), - h1( $db->{name} ), - qq|
|, $db->{description}, qq|
|, +sub search_form { + qq||, start_form( -action => self_url( query => 0 ) ), radio_group( -name => 'attr', @@ -170,23 +165,30 @@ -linebreak=> 'true', ), qq||, + end_form, + ; +} -; -print end_form; +print + start_html( + -title => $db->{name}, + -style => [ @style ], + ), + h1( $db->{name} ), + qq|
|, $db->{description}, qq|
|, +; if ( my $search = param('search') ) { - print qq|
|; + print qq| + +
+ |; my $swish = SWISH::API->new( "$dir/../var/swish/$database" ); $swish->abort_last_error if $swish->Error; - my $pager = Data::Page->new; - $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ ); - - dump_yaml( 'pager', $pager ); - my @search = (); if ( $search =~ m{(=|"|AND|OR)} ) { push @search, $search; @@ -207,12 +209,18 @@ $attr . '="' . $template . '"'; ; }; - $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge; + if ( $op =~ m{\s} ) { + my $template = $op; + $template =~ s{Q}{$v}; + $v = $attr . '="' . $template . '"'; + } else { + $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge; + } push @search, $v; my @only_input = param('only_input'); - push @search, '(' . join(') OR (', map { "input=$_" } @only_input) . ')' if @only_input; + push @search, '((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input; } else { push @search, "all=\"$search\""; } @@ -224,9 +232,13 @@ dump_yaml( 'swish_results', $swish_results ); + my $pager = Data::Page->new; + $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ ); $pager->total_entries( $swish_results->hits ); - $swish_results->seek_result( $pager->first ); + dump_yaml( 'pager', $pager ); + + $swish_results->seek_result( $pager->first - 1 ); if ( ! $pager->total_entries ) { my $no_results = 'No results for search %s'; @@ -241,19 +253,22 @@ print qq|\n\n| if $pager_html; - my $start = $pager->first; - print qq|
    \n|; + my $nr = $pager->first; + print qq|
      \n|; my $limit = $pager->entries_on_this_page; + my $nr = 1; + while ( my $result = $swish_results->next_result ) { - last if $limit-- == 0; my $data = from_json $result->property('data'); dump_yaml( 'data', $data ); - print qq|
    1. |; + my $li_class = ''; + $li_class = qq| class="z"| if $nr % 2 == 0; + print qq||; foreach my $attr ( @attr ) { next unless defined $data->{$attr}; my $v = $data->{$attr}; @@ -268,6 +283,8 @@ print qq|
      $v
      \n|; } print qq|
    2. \n|; + + last if $nr++ == $pager->last; } print qq|
    \n\n|; @@ -279,6 +296,8 @@ } +print search_form; + dump_yaml( "config databases $database", $db ); dump_yaml( 'html_markup_skip', $html_markup_skip );