use DBI;
use URI::Escape;
use HTML::Template::Pro;
+
#
# Libre10
#
$mode = $q->param("mode");
$width = $q->param("width");
$height = $q->param("height");
-$start = $q->param("start");
-$rows = $q->param("rows");
-if ($start eq ""){$start="0";}
-if ($rows eq ""){$rows="10";}
+$start = $q->param("start");
+$rows = $q->param("rows");
+if ( $start eq "" ) { $start = "0"; }
+if ( $rows eq "" ) { $rows = "10"; }
-my $url = $confdata->{solrurl};
-my $solr = WebService::Solr->new($url);
-my $template = HTML::Template::Pro->new(filename=>"./template/desktop_top.tmpl",die_on_bad_params=>0);
+my $url = $confdata->{solrurl};
+my $solr = WebService::Solr->new($url);
+my $template = HTML::Template::Pro->new(
+ filename => "./template/desktop_top.tmpl",
+ die_on_bad_params => 0
+);
print $q->header( -type => "text/html", -charset => "utf-8" );
-$template->param(mode=>$mode);
-$template -> param(width=>$width);
-$template -> param(height=>$height);
-$template -> param(start=>$start);
-$template -> param(rows=>$rows);
+$template->param( mode => $mode );
+$template->param( width => $width );
+$template->param( height => $height );
+$template->param( start => $start );
+$template->param( rows => $rows );
-$bstart=int($start)-int($rows);
-$nstart=int($start)+int($rows);
-if ($bstart<0){
- $bstart=0;
+$bstart = int($start) - int($rows);
+$nstart = int($start) + int($rows);
+if ( $bstart < 0 ) {
+ $bstart = 0;
}
-$blink = "pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$bstart&rows=$rows";
-$nlink = "pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$nstart&rows=$rows";
-$template->param(blink=>$blink);
-$template->param(nlink=>$nlink);
+$blink =
+"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$bstart&rows=$rows";
+$nlink =
+"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$nstart&rows=$rows";
+$template->param( blink => $blink );
+$template->param( nlink => $nlink );
if ( length $search_text > 0 ) {
- $template->param(text=>$search_text);
- $template->param(show_result=>"true");
- $template->param(search_top=>"0");
+ $template->param( text => $search_text );
+ $template->param( show_result => "true" );
+ $template->param( search_top => "0" );
my $query = WebService::Solr::Query->new(
{ text => decode( 'utf-8', $search_text ) } );
my $response = $solr->search(
$query,
{
'rows' => $rows,
- 'start' => $start,
+ 'start' => $start,
'group.limit' => '30',
'group.field' => 'title_group',
'group' => true,
}
);
- my $hits = $response->content;
- my %hits = %$hits;
- my $response_header = $hits{grouped}{title_group}{groups};
- my @response_header = @$response_header;
- my @print_group_arrays=();
+ my $hits = $response->content;
+ my %hits = %$hits;
+ my $response_header = $hits{grouped}{title_group}{groups};
+ my @response_header = @$response_header;
+ my @print_group_arrays = ();
foreach my $group (@response_header) {
- my $textarray = $group->{doclist}{docs};
- my @textarray = @$textarray;
- my %print_group_array=&printGroupResults(
+ my $textarray = $group->{doclist}{docs};
+ my @textarray = @$textarray;
+ my %print_group_array = &printGroupResults(
$group->{doclist}{numFound},
$textarray[0]->{title_group},
$search_text, $textarray, $response->content->{highlighting}
);
- push (@print_group_arrays, \%print_group_array);
+ push( @print_group_arrays, \%print_group_array );
}
- $template->param(group=>\@print_group_arrays);
+ $template->param( group => \@print_group_arrays );
}
else {
- $template->param(search_top=>true);
+ $template->param( search_top => true );
}
sub printGroupResults() {
( $hitsnum, $title, $search_text, $hits, $hits_hl ) = @_;
my $result_group;
- my @print_page_arrays=();
- $template->param(show_result=>1);
+ my @print_page_arrays = ();
+ $template->param( show_result => 1 );
foreach $doc (@$hits) {
( $pagenum, $path, $linkpath ) =
( $doc->{page}, $doc->{path_id}, $doc->{path_id} );
- my $findPageSQL = "SELECT startpage,title_id from pdffile WHERE id = '$path';";
- my $sth = $sqldbi->prepare($findPageSQL);
+ my $findPageSQL =
+ "SELECT startpage,title_id from pdffile WHERE id = '$path';";
+ my $sth = $sqldbi->prepare($findPageSQL);
$sth->execute;
- $dbarray=$sth->fetchrow_arrayref;
+ $dbarray = $sth->fetchrow_arrayref;
$showpagenum = $pagenum + $dbarray->[0];
- $ref="title=" . uri_escape( $dbarray->[1] ) . "&pagenum=$showpagenum&mode=$mode&width=$width&height=$height";
- my %print_page_array=(page=>$showpagenum,hl_text=>$hits_hl->{ $doc->{id} }{text}[0],refaddr=>$ref);
- @print_page_array=($print_page_array);
- push (@print_page_arrays, \%print_page_array);
+ $ref =
+ "title="
+ . uri_escape( $dbarray->[1] )
+ . "&pagenum=$showpagenum&mode=$mode&width=$width&height=$height";
+ my %print_page_array = (
+ page => $showpagenum,
+ hl_text => $hits_hl->{ $doc->{id} }{text}[0],
+ refaddr => $ref
+ );
+ @print_page_array = ($print_page_array);
+ push( @print_page_arrays, \%print_page_array );
}
- %print_group_array=(text=>$title,search_num=>$hitsnum,search_result=>\@print_page_arrays);
+ %print_group_array = (
+ text => $title,
+ search_num => $hitsnum,
+ search_result => \@print_page_arrays
+ );
return %print_group_array;
}
print $template->output();