|
Lines 21-32
require Exporter;
Link Here
|
| 21 |
use C4::Context; |
21 |
use C4::Context; |
| 22 |
use C4::Biblio; # GetMarcFromKohaField |
22 |
use C4::Biblio; # GetMarcFromKohaField |
| 23 |
use C4::Koha; # getFacets |
23 |
use C4::Koha; # getFacets |
| 24 |
use Lingua::Stem; |
|
|
| 25 |
use C4::Search::PazPar2; |
24 |
use C4::Search::PazPar2; |
| 26 |
use XML::Simple; |
25 |
use XML::Simple; |
| 27 |
use C4::Dates qw(format_date); |
26 |
use C4::Dates qw(format_date); |
| 28 |
use C4::XSLT; |
27 |
use C4::XSLT; |
| 29 |
use C4::Branch; |
28 |
use C4::Branch; |
|
|
29 |
require Lingua::Stem::Snowball; |
| 30 |
|
30 |
|
| 31 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
31 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
| 32 |
|
32 |
|
|
Lines 736-742
sub _detect_truncation {
Link Here
|
| 736 |
|
736 |
|
| 737 |
# STEMMING |
737 |
# STEMMING |
| 738 |
sub _build_stemmed_operand { |
738 |
sub _build_stemmed_operand { |
| 739 |
my ($operand) = @_; |
739 |
my ($operand, $lang) = @_; |
| 740 |
my $stemmed_operand; |
740 |
my $stemmed_operand; |
| 741 |
|
741 |
|
| 742 |
# If operand contains a digit, it is almost certainly an identifier, and should |
742 |
# If operand contains a digit, it is almost certainly an identifier, and should |
|
Lines 745-765
sub _build_stemmed_operand {
Link Here
|
| 745 |
# "014100018X" to "x ", which for a MARC21 database would bring up irrelevant |
745 |
# "014100018X" to "x ", which for a MARC21 database would bring up irrelevant |
| 746 |
# results (e.g., "23 x 29 cm." from the 300$c). Bug 2098. |
746 |
# results (e.g., "23 x 29 cm." from the 300$c). Bug 2098. |
| 747 |
return $operand if $operand =~ /\d/; |
747 |
return $operand if $operand =~ /\d/; |
|
|
748 |
|
| 749 |
my $stemmer = Lingua::Stem::Snowball->new( lang => $lang, |
| 750 |
encoding => "UTF-8" ); |
| 748 |
|
751 |
|
| 749 |
# FIXME: the locale should be set based on the user's language and/or search choice |
|
|
| 750 |
my $stemmer = Lingua::Stem->new( -locale => 'EN-US' ); |
| 751 |
|
| 752 |
# FIXME: these should be stored in the db so the librarian can modify the behavior |
| 753 |
$stemmer->add_exceptions( |
| 754 |
{ |
| 755 |
'and' => 'and', |
| 756 |
'or' => 'or', |
| 757 |
'not' => 'not', |
| 758 |
} |
| 759 |
); |
| 760 |
my @words = split( / /, $operand ); |
752 |
my @words = split( / /, $operand ); |
| 761 |
my $stems = $stemmer->stem(@words); |
753 |
|
| 762 |
for my $stem (@$stems) { |
754 |
for my $word (@words) { |
|
|
755 |
my $stem = $stemmer->stem($word); |
| 763 |
$stemmed_operand .= "$stem"; |
756 |
$stemmed_operand .= "$stem"; |
| 764 |
$stemmed_operand .= "?" |
757 |
$stemmed_operand .= "?" |
| 765 |
unless ( $stem =~ /(and$|or$|not$)/ ) || ( length($stem) < 3 ); |
758 |
unless ( $stem =~ /(and$|or$|not$)/ ) || ( length($stem) < 3 ); |
|
Lines 847-853
See verbose embedded documentation.
Link Here
|
| 847 |
=cut |
840 |
=cut |
| 848 |
|
841 |
|
| 849 |
sub buildQuery { |
842 |
sub buildQuery { |
| 850 |
my ( $operators, $operands, $indexes, $limits, $sort_by, $scan ) = @_; |
843 |
my ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang ) = @_; |
| 851 |
|
844 |
|
| 852 |
warn "---------\nEnter buildQuery\n---------" if $DEBUG; |
845 |
warn "---------\nEnter buildQuery\n---------" if $DEBUG; |
| 853 |
|
846 |
|
|
Lines 1038-1044
sub buildQuery {
Link Here
|
| 1038 |
|
1031 |
|
| 1039 |
# Handle Stemming |
1032 |
# Handle Stemming |
| 1040 |
my $stemmed_operand; |
1033 |
my $stemmed_operand; |
| 1041 |
$stemmed_operand = _build_stemmed_operand($operand) |
1034 |
$stemmed_operand = _build_stemmed_operand($operand, $lang) |
| 1042 |
if $stemming; |
1035 |
if $stemming; |
| 1043 |
warn "STEMMED OPERAND: >$stemmed_operand<" if $DEBUG; |
1036 |
warn "STEMMED OPERAND: >$stemmed_operand<" if $DEBUG; |
| 1044 |
|
1037 |
|