File: query

package info (click to toggle)
libace-perl 1.92-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,012 kB
  • sloc: perl: 7,763; ansic: 7,420; makefile: 81
file content (78 lines) | stat: -rwxr-xr-x 1,838 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl

use strict;
use vars qw/$DB $URL %PAPERS/;

use Ace 1.38;
use CGI 2.42 qw/:standard :html3 escape/;
use CGI::Carp qw/fatalsToBrowser/;
use Ace::Browser::AceSubs qw(:DEFAULT DoRedirect);
use Ace::Browser::SearchSubs;

# zero globals in utilities
my $query          = param('query');
my $offset         = AceSearchOffset();

$URL = url();
$URL=~s!^http://[^/]+!!;

# fetch database handle
$DB = OpenDatabase() || AceError("Couldn't open database.");

my ($objs,$count);
($objs,$count) = do_search($query,$offset) if $query;
DoRedirect(@$objs) if $count==1;

PrintTop(undef,undef,'AceDB Query');
display_search_form();
display_search($objs,$count,$offset,$query) if $query;

PrintBottom();

sub display_search_form {
  print p({-class=>'small'},
	  "Type in a search term using the Ace query language. Separate multiple statements with semicolons.",
	  br,
	 "Examples: ",
	  ul(
	     li(
		[cite({-style=>'font-size: 10pt'},'find Author COUNT Paper > 100'),
		 cite({-style=>'font-size: 10pt'},'find Author IS "Garvin*" ; >Laboratory; >Staff')
		]),br,
		a({-href=>"http://probe.nalusda.gov:8000/aboutacedbquery.html",
		   -style=>'font-size: 10pt'},
		  'Documentation and more examples')
		),
	  );
  print start_form,
        textfield(-name=>'query',-size=>80),br,
        submit(-label=>'Query'),
        end_form;
}









sub do_search {
  my ($query,$offset) = @_;
  my $count;
  my (@objs) = $DB->find(-query=> $query,
			 -count  => MAXOBJECTS,
			 -offset => $offset,
			 -total => \$count);
  return unless @objs;
  return (\@objs,$count);
}

sub display_search {
    my ($objs,$count,$offset,$query) = @_;
    print p(strong($count),"objects satisfy the query",strong($query));
    my @objects = map { a({-href=>Object2URL($_)},"$_") } @$objs;
    AceResultsTable(\@objects,$count,$offset) if @objects;
}