109 |
sub read_config_txt { |
sub read_config_txt { |
110 |
my ( $file ) = @_; |
my ( $file ) = @_; |
111 |
my $input; |
my $input; |
112 |
foreach ( split(/[\n\r]+/, read_file( "$dir/$path/$path-$file.txt" ) ) ) { |
my $path ="$dir/$path/$path-$file.txt"; |
113 |
|
if ( ! -e $path ) { |
114 |
|
warn "missing $path"; |
115 |
|
return; |
116 |
|
} |
117 |
|
foreach ( split(/[\n\r]+/, read_file( $path ) ) ) { |
118 |
my ( $val,$label ) = split(/\s*\t\s*/,$_,2); |
my ( $val,$label ) = split(/\s*\t\s*/,$_,2); |
119 |
push @{ $input->{ '-values' } }, $val; |
push @{ $input->{ '-values' } }, $val; |
120 |
$input->{ '-labels' }->{$val} = $label; |
$input->{ '-labels' }->{$val} = $label; |
132 |
warn dump( $attr_labels, $attr_operators ); |
warn dump( $attr_labels, $attr_operators ); |
133 |
|
|
134 |
my $only_input; |
my $only_input; |
135 |
|
my $inputs_available = 0; |
136 |
|
|
137 |
foreach ( @{ $db->{input} } ) { |
foreach ( @{ $db->{input} } ) { |
138 |
my $input = $_->{name} || die "no name in ",dump( $_ ); |
my $input = $_->{name} || die "no name in ",dump( $_ ); |
139 |
if ( ! $only_input->{'-labels'}->{$input} ) { |
if ( ! $only_input->{'-labels'}->{$input} ) { |
140 |
push @{ $only_input->{'-values'} }, $input; |
push @{ $only_input->{'-values'} }, $input; |
141 |
$only_input->{'-labels'}->{$input} = $_->{description} || $input; |
$only_input->{'-labels'}->{$input} = $_->{description} || $input; |
142 |
|
$inputs_available++; |
143 |
} |
} |
144 |
} |
} |
145 |
|
|
152 |
sub search_form { |
sub search_form { |
153 |
qq|<a name="form"></a>|, |
qq|<a name="form"></a>|, |
154 |
start_form( -action => self_url( query => 0 ) ), |
start_form( -action => self_url( query => 0 ) ), |
155 |
radio_group( |
checkbox_group( |
156 |
-name => 'attr', |
-name => 'attr', |
157 |
%$attr_labels, |
%$attr_labels, |
158 |
# -linebreak => 0, |
# -linebreak => 0, |
159 |
), |
), |
160 |
textfield( -name => 'search' ), |
textfield( -name => 'search' ), |
161 |
popup_menu( -name => 'attr_operator', %$attr_operators ), |
$attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '', |
162 |
submit, |
submit, |
163 |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
164 |
# we need current_page fixed at 1 so that every submit through form will reset it |
# we need current_page fixed at 1 so that every submit through form will reset it |
165 |
qq|<input type=hidden name=current_page value=1 >|, |
qq|<input type=hidden name=current_page value=1 >|, |
166 |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
167 |
qq|<div id=inputs>|, |
qq|<div id=inputs>|, |
168 |
h2( 'Select input' ), |
$inputs_available > 1 ? |
169 |
|
h2( 'Select input' ) . |
170 |
checkbox_group( |
checkbox_group( |
171 |
-name => 'only_input', |
-name => 'only_input', |
172 |
%$only_input, |
%$only_input, |
173 |
-linebreak=> 'true', |
-linebreak=> 'true', |
174 |
), |
) : '', |
175 |
qq|</div>|, |
qq|</div>|, |
176 |
end_form, |
end_form, |
177 |
; |
; |
198 |
$swish->abort_last_error if $swish->Error; |
$swish->abort_last_error if $swish->Error; |
199 |
|
|
200 |
my @search = (); |
my @search = (); |
201 |
|
my @attrs = param('attr'); |
202 |
|
my $op = param('attr_operator'); |
203 |
|
|
204 |
if ( $search =~ m{(=|"|AND|OR)} ) { |
if ( $search =~ m{(=|"|AND|OR)} ) { |
205 |
push @search, $search; |
push @search, $search; |
206 |
} elsif ( my $op = param('attr_operator') ) { |
} elsif ( @attrs ) { |
207 |
my $attr = param('attr'); |
|
208 |
my $v = $search; |
$op ||= 'Q*'; |
209 |
$v =~ s/^\s+//; |
my @or; |
210 |
warn "-- v: $v\n"; |
foreach my $attr ( @attrs ) { |
211 |
sub rewrite { |
my $v = $search; |
212 |
my ( $whitespace, $v ) = @_; |
$v =~ s/^\s+//; |
213 |
warn "## filter $op $whitespace $v\n"; |
warn "-- v: $v\n"; |
214 |
my $template = $op; |
sub rewrite { |
215 |
$template =~ s{Q}{$v}; |
my ( $attr, $whitespace, $v ) = @_; |
216 |
$whitespace = " AND " if $whitespace; |
warn "## filter $op $whitespace $v\n"; |
217 |
|
my $template = $op; |
218 |
return |
$template =~ s{Q}{$v}; |
219 |
$whitespace . |
$whitespace = " AND " if $whitespace; |
220 |
$attr . '="' . $template . '"'; |
|
221 |
; |
return |
222 |
}; |
$whitespace . |
223 |
if ( $op =~ m{\s} ) { |
$attr . '="' . $template . '"'; |
224 |
my $template = $op; |
; |
225 |
$template =~ s{Q}{$v}; |
}; |
226 |
$v = $attr . '="' . $template . '"'; |
if ( $op =~ m{\s} ) { |
227 |
} else { |
my $template = $op; |
228 |
$v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge; |
$template =~ s{Q}{$v}; |
229 |
|
$v = $attr . '="' . $template . '"'; |
230 |
|
} else { |
231 |
|
$v =~ s{(\s*)(\S+)}{rewrite($attr,$1,$2)}ge; |
232 |
|
} |
233 |
|
|
234 |
|
push @or, $v; |
235 |
|
|
236 |
} |
} |
237 |
|
push @search, '(' . join(') OR (', @or) . ')'; |
238 |
|
|
|
push @search, $v; |
|
|
|
|
|
my @only_input = param('only_input'); |
|
|
push @search, '((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input; |
|
239 |
} else { |
} else { |
240 |
push @search, "all=\"$search\""; |
push @search, "all=\"$search\""; |
241 |
} |
} |
242 |
|
|
243 |
my $q = '(' . join(') AND (', @search) . ')'; |
my $q = '(' . join(') AND (', @search) . ')'; |
244 |
$q =~ s{\(\((.+)\)\)}{($1)}; |
|
245 |
|
my @only_input = param('only_input'); |
246 |
|
$q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input; |
247 |
|
|
248 |
warn "# query: $q\n"; |
warn "# query: $q\n"; |
249 |
my $swish_results = $swish->query( $q ); |
my $swish_results = $swish->query( $q ); |
250 |
|
|