-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintable
executable file
·144 lines (121 loc) · 4.55 KB
/
printable
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl
# CGI script provides search page of Textpresso system
#
# Copyright (c) Hans-Michael Muller 2007.
use strict;
# The following line needs adjustments for each implementation
use lib "/usr/local/lib/textpresso/displaying/ecoli/";
# end line that needs adjustments
use CGI;
use POSIX;
use TextpressoDisplayGlobals;
use TextpressoDisplayTasks;
use TextpressoDatabaseGlobals;
use TextpressoDatabaseQuery;
use TextpressoDatabaseSearch;
my $query = new CGI;
my $myself = $query->url(-absolute => 1);
(my $base = $query->url(-base => 1)) =~ s/http\:\/\///g;
my @cookies = ();
foreach my $opt (keys % {(DB_DISPLAY_FIELDS)}, 'supplementals', 'epp', 'matches') {
if (defined($query->param("disp_$opt"))) {
push @cookies, $query->cookie( -name => "opt_$opt",
-value => $query->param("disp_$opt"),
-domain => $base,
-expires => '+365d');
}
}
my $location = PrintTop($query, $myself, 0, @cookies);
########################################################
# Read in the HTML links up-front
my $infile = "<" . HTML_LINKTEMPLATES;
my @regexps = ();
my @urls = ();
my @explanations = ();
open (IN, $infile);
while (my $line = <IN>) {
chomp ($line);
next if (!($line =~ /^http/));
(my $u, my $r, my $e) = split (/[ \t]+/, $line);
push @urls, $u;
push @regexps, $r;
push @explanations, $e;
}
########################################################
# Process form here
my $starttime = time();
my $tpquery;
my %results;
foreach my $opt (keys % {(DB_DISPLAY_FIELDS)}, 'supplementals', 'epp', 'matches') {
if ((defined($query->cookie("opt_$opt")) && (!defined($query->param("disp_$opt"))))) {
$query->param(-name => "disp_$opt",
-value => $query->cookie("opt_$opt"));
}
}
if (defined($query->param('dodisplayquery'))) {
($tpquery, my $dummy) = ParseInputFields($query, "");
}
my $filteredfilename = $query->param('filteredfilename');
%results = textpressosearch($tpquery, 0, $filteredfilename, $query->param('mode'));
my %ltk = littgtkey(\%results); # this also `cleans' up empty entries of results
my @ltks = keys % ltk;
my $doctotal = scalar(@ltks);
my $clstrtotal = 0;
foreach my $l (@ltks) {
$clstrtotal += scalar (@{$ltk{$l}});
}
# End of process form
# Print output here
if (defined($query->param('dodisplayquery'))) {
print CreateQueryDisplay($query, $tpquery);
print $query->p;
}
if (%results) {
my @highlightkeywords = makehighlightterms($tpquery, 'keyword') if ($query->param("disp_searchterm-highlighting") eq 'on');
my %invlist = preparesortresults(\%ltk, \%results, $query->param('sort'));
my @sorted = ();
if ($query->param('sort') =~ /(score|hits|year)/i) {
@sorted = (sort numerically keys % invlist);
} else {
@sorted = (sort alphabetically keys % invlist);
}
print $query->hr;
if ($doctotal < 500) {
print $query->span({-style => "font-weight:bold;"}, "$clstrtotal matches found in $doctotal documents. ");
print $query->span({-style => "font-weight:bold;"}, "Results sorted by ", $query->param('sort'), ".");
my $resulttable = new TextpressoTable;
$resulttable->init;
$resulttable->addtablerow();
foreach my $k (@sorted) {
foreach my $l (sort @{$invlist{$k}}) {
my $entrytable = new TextpressoTable;
$entrytable->init;
my $score = 0;
(my $lit, my $tgt, my $key) = split(/\ -\ /, $l);
foreach my $clstr (@{$ltk{$l}}) {
$score += $results{$lit}{$key}{$tgt}{$clstr};
}
my @highlights = (@highlightkeywords, makehighlightterms($tpquery, 'category', $lit, $tgt, $key)) if ($query->param("disp_searchterm-highlighting") eq 'on');
my $rightcontent = $query->div({-align => "right"},
$query->span({-style => "font-weight:bold;"}, "Score: ") . sprintf("%4.2f", $score));
$entrytable->addtablerow($rightcontent);
my $var = "(" . join("|", @highlights) . ")";
makeentry($query, $entrytable, $l, \@{$ltk{$l}}, \%results, \@urls, \@regexps, \@explanations, $var);
$resulttable->addtablerow($entrytable->maketable($query, tablestyle => 'borderless',
DSP_HDRCOLOR => 'black', DSP_HDRSIZE => '75%',
width => "100%"));
}
}
print $resulttable->maketable($query,
tablestyle => 'headerbackground', cellspacing => '0',
cellpadding => '0', border => '1',
DSP_HDRBCKGRND => '#696969', width => "100%");
} else {
print $query->span({-style => "font-weight:bold;"}, "$doctotal documents: too many entries! Aborting!");
}
}
# End print output
my $extramessage = "All rights reserved.";
PrintBottom($query, $extramessage);
sub numerically { $b <=> $a }
sub alphabetically { $a cmp $b }