2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web', 'Frey::Config', 'Frey::jQuery'; |
|
with 'Frey::Config'; |
|
|
with 'Frey::jQuery'; |
|
6 |
|
|
7 |
use Search::Estraier; |
use Search::Estraier; |
8 |
use JSON::Syck; |
use JSON::Syck; |
24 |
); |
); |
25 |
|
|
26 |
has 'on_page' => ( |
has 'on_page' => ( |
27 |
documentation => 'numer of items on page', |
documentation => 'number of items on page', |
28 |
is => 'rw', |
is => 'rw', |
29 |
isa => 'Int', |
isa => 'Int', |
30 |
default => 30, |
default => 20, |
31 |
); |
); |
32 |
|
|
33 |
has 'sort' => ( |
has 'sort' => ( |
44 |
my $v = { |
my $v = { |
45 |
search => $search, |
search => $search, |
46 |
page => $page, |
page => $page, |
47 |
max_page => $page, |
max_page => 0, |
48 |
id => time() . rand(99), |
id => time() . rand(99), |
49 |
}; |
}; |
50 |
|
|
51 |
sub next_page { |
sub next_page { |
52 |
my $self = shift; |
my $self = shift; |
53 |
|
my $v = shift; |
54 |
my $json = $self->html_escape( JSON::Syck::Dump( $v ) ); |
my $json = $self->html_escape( JSON::Syck::Dump( $v ) ); |
55 |
|
|
56 |
my $message = join("\n", @_); |
my $message = join("\n", @_); |
57 |
|
|
58 |
# <textarea id="json" style="display:none"> |
my $next_page = $v->{page} + 1; |
59 |
|
|
60 |
return qq| |
return qq| |
61 |
<div id="next_page"> |
<div id="next_page_$next_page"> |
62 |
$message |
$message |
63 |
<textarea id="json"> |
<textarea id="json" style="display:none">$json</textarea> |
|
$json |
|
|
</textarea> |
|
64 |
</div> |
</div> |
65 |
| |
| |
66 |
; |
; |
68 |
|
|
69 |
if (! $search || $search =~ m/^\s*$/) { |
if (! $search || $search =~ m/^\s*$/) { |
70 |
$v->{status} = 'Enter search query'; |
$v->{status} = 'Enter search query'; |
71 |
return $self->next_page; |
return $self->next_page( $v ); |
72 |
} |
} |
73 |
|
|
74 |
$search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/); |
$search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/); |
75 |
|
$v->{search} = $search; |
76 |
|
|
77 |
my $node = new Search::Estraier::Node(%{ $self->config->{estraier} }); |
my $node = new Search::Estraier::Node(%{ $self->config->{estraier} }); |
78 |
|
|
81 |
|
|
82 |
my $cond = new Search::Estraier::Condition; |
my $cond = new Search::Estraier::Condition; |
83 |
$cond->set_phrase( $search ); |
$cond->set_phrase( $search ); |
84 |
$cond->set_max( $on_page * $page ); ## FIXME * $page is needed by hest 1.3.8 |
$cond->set_max( $on_page ); |
85 |
$cond->set_skip( $skip ); |
$cond->set_skip( $skip ); |
86 |
$cond->set_order( $self->sort ) if $self->sort; |
$cond->set_order( $self->sort ) if $self->sort; |
87 |
|
|
89 |
|
|
90 |
my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) ); |
my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) ); |
91 |
|
|
92 |
my $out; |
my $out = qq|<!-- page $page -->|; |
93 |
|
|
94 |
if (defined($nres)) { |
if (defined($nres)) { |
95 |
|
|
98 |
|
|
99 |
if ($v->{hits} == 0) { |
if ($v->{hits} == 0) { |
100 |
$v->{status} = qq{<strong>No results for your search.</strong>}; |
$v->{status} = qq{<strong>No results for your search.</strong>}; |
101 |
return $self->next_page; |
return $self->next_page( $v, qq|<strong>No results found.</strong>| ); |
102 |
} elsif ($nres->doc_num == 0) { |
} elsif ($nres->doc_num == 0) { |
103 |
$v->{status} = qq{<strong>Error getting results for page $page.</strong>}; |
$v->{status} = qq{<strong>Error getting results for page $page.</strong>}; |
104 |
return $self->next_page('<strong>No results found.</strong>'); |
return $self->next_page( $v ); |
105 |
} |
} |
106 |
|
|
107 |
$v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page ); |
$v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page ); |
146 |
|
|
147 |
my $result = q| |
my $result = q| |
148 |
<div class="result"> |
<div class="result"> |
149 |
<h1><% attr_regex( $rdoc, '@title' ) %></h1> |
<span class="nr"><% $nr %></span> |
150 |
|
<h1 title="<% $nr %>"><% attr_regex( $rdoc, '@title' ) %></h1> |
151 |
<p> |
<p> |
152 |
<% html_snippet( $rdoc->snippet ) %> |
<% html_snippet( $rdoc->snippet ) %> |
153 |
</p> |
</p> |
|
<span style="color: #888"><% $nr %></span> |
|
154 |
<strong><% attr_regex( $rdoc, 'source' ) %></strong> |
<strong><% attr_regex( $rdoc, 'source' ) %></strong> |
155 |
<em> |
<em> |
156 |
<% attr_regex( $rdoc, '@size' ) %> bytes |
<% attr_regex( $rdoc, '@size' ) %> bytes |
183 |
} |
} |
184 |
|
|
185 |
if ($v->{page} == $v->{max_page}) { |
if ($v->{page} == $v->{max_page}) { |
186 |
$out .= $self->next_page('<br/><strong>All results shown</strong>'); |
$out .= $self->next_page( $v, qq|<br/><strong>All results shown</strong>|); |
187 |
} else { |
} else { |
188 |
$out .= $self->next_page( |
$out .= $self->next_page( $v, qq| |
189 |
'<br/><strong>Loading results...</strong><br/>', |
<br/><strong>Loading results...</strong> |
190 |
'If you are using the scroll bar, release the mouse to see more results.' |
<br/>If you are using the scroll bar, release the mouse to see more results. |
191 |
); |
|); |
192 |
} |
} |
193 |
|
|
194 |
warn "# v = ", dump( $v ); |
warn "# v = ", dump( $v ); |
218 |
|
|
219 |
my ( $results, $status ) = $self->results_as_markup; |
my ( $results, $status ) = $self->results_as_markup; |
220 |
|
|
221 |
|
$self->add_css(q| |
222 |
|
#results { |
223 |
|
margin-top: 3em; |
224 |
|
margin-bottom: 3em; |
225 |
|
} |
226 |
|
|); |
227 |
|
|
228 |
my $html = join("\n", |
my $html = join("\n", |
229 |
qq| |
qq| |
230 |
<div id="search_form_div"> |
<div id="search_form_div"> |
241 |
</form> |
</form> |
242 |
</div> |
</div> |
243 |
|
|
244 |
<div style="margin-top: 3em;"> |
<div id="results"> |
245 |
<!-- Dynamic Content --> |
<!-- Dynamic Content --> |
246 |
$results |
$results |
|
|
|
|
<!-- Back Button Content --> |
|
|
<div style="position:absolute;top:0px;left:0px;visibility:hidden;" id="spacer">space</div> |
|
|
<!-- footer at end of results --> |
|
|
<div style="display:none;" id="footer"> |
|
|
Thanks for trying out no pager. Hope you like it. |
|
|
</div> |
|
|
|
|
247 |
</div> |
</div> |
248 |
|
|
249 |
| |
| |
252 |
return $html; |
return $html; |
253 |
} |
} |
254 |
|
|
255 |
|
__PACKAGE__->meta->make_immutable; |
256 |
|
no Moose; |
257 |
|
|
258 |
1; |
1; |