92 |
=cut |
=cut |
93 |
|
|
94 |
sub _s { |
sub _s { |
95 |
my $text = $_[1] || return; |
my $text = $_[1]; |
96 |
|
return unless defined($text); |
97 |
$text =~ s/\s\s+/ /gs; |
$text =~ s/\s\s+/ /gs; |
98 |
$text =~ s/^\s+//; |
$text =~ s/^\s+//; |
99 |
$text =~ s/\s+$//; |
$text =~ s/\s+$//; |
321 |
my $draft; |
my $draft; |
322 |
|
|
323 |
foreach my $attr_name (sort keys %{ $self->{attrs} }) { |
foreach my $attr_name (sort keys %{ $self->{attrs} }) { |
324 |
$draft .= $attr_name . '=' . $self->{attrs}->{$attr_name} . "\n"; |
next unless defined(my $v = $self->{attrs}->{$attr_name}); |
325 |
|
$draft .= $attr_name . '=' . $v . "\n"; |
326 |
} |
} |
327 |
|
|
328 |
if ($self->{kwords}) { |
if ($self->{kwords}) { |
370 |
|
|
371 |
package Search::Estraier::Condition; |
package Search::Estraier::Condition; |
372 |
|
|
373 |
use Carp qw/confess croak/; |
use Carp qw/carp confess croak/; |
374 |
|
|
375 |
use Search::Estraier; |
use Search::Estraier; |
376 |
our @ISA = qw/Search::Estraier/; |
our @ISA = qw/Search::Estraier/; |
448 |
|
|
449 |
=head2 set_options |
=head2 set_options |
450 |
|
|
451 |
$cond->set_options( SURE => 1 ); |
$cond->set_options( 'SURE' ); |
452 |
|
|
453 |
|
$cond->set_options( qw/AGITO NOIDF SIMPLE/ ); |
454 |
|
|
455 |
|
Possible options are: |
456 |
|
|
457 |
|
=over 8 |
458 |
|
|
459 |
|
=item SURE |
460 |
|
|
461 |
|
check every N-gram |
462 |
|
|
463 |
|
=item USUAL |
464 |
|
|
465 |
|
check every second N-gram |
466 |
|
|
467 |
|
=item FAST |
468 |
|
|
469 |
|
check every third N-gram |
470 |
|
|
471 |
|
=item AGITO |
472 |
|
|
473 |
|
check every fourth N-gram |
474 |
|
|
475 |
|
=item NOIDF |
476 |
|
|
477 |
|
don't perform TF-IDF tuning |
478 |
|
|
479 |
|
=item SIMPLE |
480 |
|
|
481 |
|
use simplified query phrase |
482 |
|
|
483 |
|
=back |
484 |
|
|
485 |
|
Skipping N-grams will speed up search, but reduce accuracy. Every call to C<set_options> will reset previous |
486 |
|
options; |
487 |
|
|
488 |
|
This option changed in version C<0.04> of this module. It's backwards compatibile. |
489 |
|
|
490 |
=cut |
=cut |
491 |
|
|
492 |
my $options = { |
my $options = { |
|
# check N-gram keys skipping by three |
|
493 |
SURE => 1 << 0, |
SURE => 1 << 0, |
|
# check N-gram keys skipping by two |
|
494 |
USUAL => 1 << 1, |
USUAL => 1 << 1, |
|
# without TF-IDF tuning |
|
495 |
FAST => 1 << 2, |
FAST => 1 << 2, |
|
# with the simplified phrase |
|
496 |
AGITO => 1 << 3, |
AGITO => 1 << 3, |
|
# check every N-gram key |
|
497 |
NOIDF => 1 << 4, |
NOIDF => 1 << 4, |
|
# check N-gram keys skipping by one |
|
498 |
SIMPLE => 1 << 10, |
SIMPLE => 1 << 10, |
499 |
}; |
}; |
500 |
|
|
501 |
sub set_options { |
sub set_options { |
502 |
my $self = shift; |
my $self = shift; |
503 |
my $option = shift; |
my $opt = 0; |
504 |
confess "unknown option" unless ($options->{$option}); |
foreach my $option (@_) { |
505 |
$self->{options} ||= $options->{$option}; |
my $mask; |
506 |
|
unless ($mask = $options->{$option}) { |
507 |
|
if ($option eq '1') { |
508 |
|
next; |
509 |
|
} else { |
510 |
|
croak "unknown option $option"; |
511 |
|
} |
512 |
|
} |
513 |
|
$opt += $mask; |
514 |
|
} |
515 |
|
$self->{options} = $opt; |
516 |
} |
} |
517 |
|
|
518 |
|
|