12 |
use SWISH::API; |
use SWISH::API; |
13 |
use JSON; |
use JSON; |
14 |
use Text::Unaccent::PurePerl qw/unac_string/; |
use Text::Unaccent::PurePerl qw/unac_string/; |
15 |
|
use HTML::FillInForm::Lite; |
16 |
|
use Encode; |
17 |
|
|
18 |
my $range_around = 5; |
my $range_around = 5; |
19 |
my @entries_per_page = ( 30, 50, 100, 500 ); |
my @entries_per_page = ( 30, 50, 100, 500 ); |
154 |
dump_yaml( 'style', \@style ); |
dump_yaml( 'style', \@style ); |
155 |
|
|
156 |
sub search_form { |
sub search_form { |
157 |
|
|
158 |
|
my $form_html = "$dir/$path/$path-search.html"; |
159 |
|
if ( -e $form_html ) { |
160 |
|
my $html = read_file( $form_html ); |
161 |
|
my $q = CGI->new(); |
162 |
|
my $h = HTML::FillInForm::Lite->new(); |
163 |
|
return $h->fill(\$html, $q); |
164 |
|
} |
165 |
|
|
166 |
qq|<a name="form"></a>|, |
qq|<a name="form"></a>|, |
167 |
start_form( -action => self_url( query => 0 ) ), |
start_form( -action => self_url( query => 0 ) ), |
168 |
checkbox_group( |
checkbox_group( |
203 |
|
|
204 |
if ( my $search = param('search') ) { |
if ( my $search = param('search') ) { |
205 |
|
|
206 |
$search = unac_string( $search ); |
$search = unac_string( Encode::decode('utf-8',$search) ); |
207 |
|
|
208 |
print qq| |
print qq| |
209 |
<a href="#form" class="skip" title="skip to search form">#</a> |
<a href="#form" class="skip" title="skip to search form">#</a> |
217 |
my @attrs = param('attr'); |
my @attrs = param('attr'); |
218 |
my $op = param('attr_operator'); |
my $op = param('attr_operator'); |
219 |
|
|
220 |
if ( $search =~ m{(=|"|AND|OR)} ) { |
if ( $search =~ m{(=|"|\bAND\b|\bOR\b)} ) { |
221 |
push @search, $search; |
push @search, $search; |
222 |
} elsif ( @attrs ) { |
} elsif ( @attrs ) { |
223 |
|
|
262 |
$q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input; |
$q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input; |
263 |
|
|
264 |
warn "# query: $q\n"; |
warn "# query: $q\n"; |
265 |
my $swish_results = $swish->query( $q ); |
my $search_obj = $swish->new_search_object; |
266 |
|
if ( my $sort = param('sort') ) { |
267 |
|
$search_obj->set_sort( $sort ); |
268 |
|
} |
269 |
|
my $swish_results = $search_obj->execute( $q ); |
270 |
|
|
271 |
dump_yaml( 'swish_results', $swish_results ); |
dump_yaml( 'swish_results', $swish_results ); |
272 |
|
|