<%attr> title => "Search results"
Search for:
% if ( $error ) { An error occured! $error % } else { % if ( $num_hits > 0 ) { Search results: <% $words_info %>
Displaying documents <% $first %>-<% $last %> of total <% $num_hits %> found. % foreach ( @docs ) {
<% $_->{docnr} %>. <% $_->{title} %> [<% $_->{r} %>]
<% $_->{txt} %>...
% }
<% $next %>
% } else {

Sorry, but search returned no results.
Try to produce less restrictive search query.

% } % } Powered by UdmSearch
<%once> my ( $error, $words_info, ); <%args> $q => '' # query string $np => 0 # page index (default: 0) $ps => 20 # num of results to show on a page $mode => 'all' # Mode ?? $t => '' # url status constraint for search $ul => '' # url filter for search (default: '') $ps_next => 0 # <%init> # GPL # author: Frank Breedijk, InterXion. www.interxion.com # # Based on perl frontend # author: Rohan Baxter, Ultimode Inc. rohan@ultimode.com use strict; use diagnostics; use udmDB; use udmParser; use DBI(); use CGI(); my ( $qu, $words, $error, $num_hits, $first, $last, @docs, $next, ); # Set some defaults $ENV{MySQLDB} = 'udmsearch'; $ENV{MySQLHost} = 'localhost'; $ENV{MySQLUser} = 'root'; $ENV{MySQLPass} = ''; my $self = $m->current_comp->name; my $tagstr = ""; if ($t) { $tagstr = "AND url.tag = $t"; } undef($qu); undef($words); undef($error); ($qu, $words, $error) = &udmParser::parse( $q ); if ($error eq ""){ if ($words ne ""){ # query is not empty # Connect to Database my $dbh = &udmDB::dbconnect($ENV{MySQLDB},$ENV{MySQLHost}, $ENV{MySQLUser},$ENV{MySQLPass}); # Look for stopwords in words, delete them # set up words_info to explain what is going on ($words,$words_info) = &udmDB::remove_stopwords( $dbh, $words ); if ($words eq "" && $qu ne ""){ # the only words in query are stopwords $error = "all query words are too common to search on."; } else { # Now collect word count stats for remaining words $words_info = &udmDB::get_word_stats( $dbh, $words, $words_info, $ul, $tagstr ); # Database Query # I'm puzzled why ul and tagstr work in here??? $num_hits = &udmDB::get_num_of_hits($dbh,$qu,$words,$ul,$tagstr); # Do Page Calculations (NB: It would be good to tidy this up) my $from = $np * $ps; # used in query $first = $from + 1; # num of first doc on page $last = ($np + 1) * $ps; # num of last doc on page my $ps1 = $ps + 1; # used in next query if ( $last > $num_hits){ $last = $num_hits; } $ps_next = $num_hits - $last; if ( ($ps_next > $ps )|| ($ps_next < 0)){ $ps_next = $ps; } # Finish if words do not occur in the db if ($num_hits > 0){ # Database Query: get urls with word counts my $sth; if ( $ul ne '' || ($tagstr ne '') ){ die($tagstr); $sth = &udmDB::get_url_ids_using_filter( $dbh, $qu, $words, $from, $ps1, $ul, $tagstr ); } else { $sth = &udmDB::get_url_ids( $dbh, $qu, $words, $from, $ps1 ); } my $rows = $sth->rows(); # Determine if there are more results than can fit on a page my $isnext = 0; my $i=0; if ($rows > $ps){ $rows = $ps; $isnext = 1; } # Output the each of the results found my $url_in = "-1"; my $url_id = ""; while ($i < $rows){ $i++; my @row = $sth->fetchrow_array; $url_id = $row[0]; if ($url_in eq "-1"){ $url_in = "$url_id"; } else { $url_in .= ",$url_id"; } } if ($url_in ne "-1"){ my $sth2 = &udmDB::get_docs($dbh, $qu, $words, $url_in); my $docnr = $from + 1; undef(@docs); while (my $data = $sth2->fetchrow_hashref){ $data->{docnr} = $docnr; push @docs, $data; $docnr++; } } # q my $prevp = 0; my $nextp = 0; $next = " "; if ($np > 0){ $prevp = $np - 1; $next = "[< < Prev $ps]   "; } if ($isnext == 1){ $nextp = $np + 1; $next .= "[Next $ps_next > >]"; } $sth->finish(); } } $dbh->disconnect(); } }