--- trunk/vhost/webpac2.cgi 2009/04/23 10:59:01 1143 +++ trunk/vhost/webpac2.cgi 2009/04/24 16:58:09 1149 @@ -7,9 +7,10 @@ use CGI::Carp qw/fatalsToBrowser/; use File::Slurp; use YAML; -use Search::Estraier; use Data::Page; use Data::Dump qw/dump/; +use SWISH::API; +use JSON; my $range_around = 5; my $entries_per_page = 30; @@ -143,10 +144,8 @@ print qq|
|; - my $node = Search::Estraier::Node->new( - url => $config->{hyperestraier}->{masterurl} . '/node/' . $database, - croak_on_error => 1, - ); + my $swish = SWISH::API->new( "$dir/../var/swish/$database" ); + $swish->abort_last_error if $swish->Error; param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed? my $pager = Data::Page->new; @@ -155,33 +154,32 @@ dump_yaml( 'pager', $pager ); - my $cond = Search::Estraier::Condition->new( debug => $debug ); - $cond->set_phrase( $search ); - $cond->set_skip( $pager->skipped ); - $cond->set_max( $pager->entries_per_page ); + my @search = ( "xml=$search" ); - if ( my $op = param('attr_operator') ) { - $cond->add_attr( param('attr') . " $op " . param('search') ); - } +# if ( my $op = param('attr_operator') ) { +# $cond->add_attr( param('attr') . " $op " . param('search') ); +# } - foreach my $i ( param('only_input') ) { - $cond->add_attr( '@uri STRBW file:///search/' . $database . '/' . $i ); - } + my @only_input = param('only_input'); + push @search, '(' . join(') or (', @only_input) . ')' if @only_input; - my $nres = $node->search( $cond, 0 ); - $pager->total_entries( $nres->hits ); + my $q = '(' . join(') and (', @search) . ')'; + warn "# query: $q\n"; + my $swish_results = $swish->query( $q ); + $swish->abort_last_error if $swish->Error; - dump_yaml( 'cond', $cond ); - dump_yaml( 'nres', $nres ); + dump_yaml( 'swish_results', $swish_results ); - if ( ! $nres ) { + $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; } else { my $results = "%d results for search '%s' showing results %d - %d on page %d"; - printf qq|
$results
\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page; + printf qq|
$results
\n\n|, $pager->total_entries, $search, $pager->first, $pager->last, $pager->current_page; my $pager_html = join("\n", show_pager( $pager )); @@ -190,19 +188,20 @@ my $start = $pager->first; print qq|
    \n|; - foreach my $i ( 1 .. $nres->doc_num ) { - my $rdoc = $nres->get_doc( $i - 1 ); + while ( my $result = $swish_results->next_result ) { + my $data = from_json $result->property('data'); + print qq|
  1. |; foreach my $attr ( @attr ) { - my $v = $rdoc->attr( $attr ); - if ( defined $v && $html_markup && ! $html_markup_skip->{$attr} ) { + next unless defined $data->{$attr}; + my $v = $data->{$attr}; + if ( $html_markup && ! $html_markup_skip->{$attr} ) { eval "\$v = $html_markup->$attr( \$v );"; if ( $@ ) { warn "disable html markup for $attr: $@"; $html_markup_skip->{$attr} = $@; } } - next unless defined $v; print qq|
    $v
    \n|; } print qq|
  2. \n|; @@ -217,7 +216,6 @@ } -dump_yaml( 'estraier', $estraier ); dump_yaml( 'db', $db ); dump_yaml( 'html_markup_skip', $html_markup_skip );