View | Details | Raw Unified | Return to bug 3172
Collapse All | Expand All

(-)a/C4/Output.pm (-2 / +16 lines)
Lines 39-51 BEGIN { Link Here
39
    require Exporter;
39
    require Exporter;
40
    @ISA    = qw(Exporter);
40
    @ISA    = qw(Exporter);
41
	@EXPORT_OK = qw(&output_ajax_with_http_headers &is_ajax); # More stuff should go here instead
41
	@EXPORT_OK = qw(&output_ajax_with_http_headers &is_ajax); # More stuff should go here instead
42
	%EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
42
	%EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
43
								&output_ajax_with_http_headers &output_html_with_http_headers)],
43
								&output_ajax_with_http_headers &output_html_with_http_headers)],
44
					ajax =>[qw(&output_ajax_with_http_headers is_ajax)],
44
					ajax =>[qw(&output_ajax_with_http_headers is_ajax)],
45
					html =>[qw(&output_html_with_http_headers)]
45
					html =>[qw(&output_html_with_http_headers)]
46
				);
46
				);
47
    push @EXPORT, qw(
47
    push @EXPORT, qw(
48
        &themelanguage &gettemplate setlanguagecookie pagination_bar
48
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
49
    );
49
    );
50
    push @EXPORT, qw(
50
    push @EXPORT, qw(
51
        &output_html_with_http_headers
51
        &output_html_with_http_headers
Lines 208-213 sub setlanguagecookie { Link Here
208
    );
208
    );
209
}
209
}
210
210
211
sub getlanguagecookie {
212
    my ($query) = @_;
213
    my $lang;
214
    if ($query->cookie('KohaOpacLanguage')){
215
        $lang = $query->cookie('KohaOpacLanguage') ;
216
    }else{
217
        $lang = $ENV{HTTP_ACCEPT_LANGUAGE};
218
        
219
    }
220
    $lang = substr($lang, 0, 2);
221
222
    return $lang;
223
}
224
211
=item pagination_bar
225
=item pagination_bar
212
226
213
   pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
227
   pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
(-)a/C4/Search.pm (-17 / +10 lines)
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
(-)a/Makefile.PL (-1 / +1 lines)
Lines 562-568 WriteMakefile( Link Here
562
                            'JSON'                             => 2.07, # Needed by admin/item_circulation_alerts.pl
562
                            'JSON'                             => 2.07, # Needed by admin/item_circulation_alerts.pl
563
                            'LWP::Simple'                      => 1.41,
563
                            'LWP::Simple'                      => 1.41,
564
                            'LWP::UserAgent'                   => 2.033,
564
                            'LWP::UserAgent'                   => 2.033,
565
                            'Lingua::Stem'                     => 0.82,
565
                            'Lingua::Stem::Snowball'           => 0.952, # optional
566
                            'List::Util'                       => 1.18,
566
                            'List::Util'                       => 1.18,
567
                            'List::MoreUtils'                  => 0.21,
567
                            'List::MoreUtils'                  => 0.21,
568
                            'Locale::Language'                 => 2.07,
568
                            'Locale::Language'                 => 2.07,
(-)a/about.pl (-1 / +1 lines)
Lines 94-100 HTML::Scrubber Link Here
94
JSON
94
JSON
95
LWP::Simple
95
LWP::Simple
96
LWP::UserAgent
96
LWP::UserAgent
97
Lingua::Stem
97
Lingua::Stem::Snowball
98
List::Util
98
List::Util
99
List::MoreUtils
99
List::MoreUtils
100
Locale::Language
100
Locale::Language
(-)a/catalogue/search.pl (-1 / +2 lines)
Lines 419-425 my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit Link Here
419
my @results;
419
my @results;
420
420
421
## I. BUILD THE QUERY
421
## I. BUILD THE QUERY
422
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by,$scan);
422
my $lang = C4::Output::getlanguagecookie($cgi);
423
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by,$scan,$lang);
423
424
424
## parse the query_cgi string and put it into a form suitable for <input>s
425
## parse the query_cgi string and put it into a form suitable for <input>s
425
my @query_inputs;
426
my @query_inputs;
(-)a/opac/opac-search.pl (-2 / +2 lines)
Lines 334-340 my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_ Link Here
334
my @results;
334
my @results;
335
335
336
## I. BUILD THE QUERY
336
## I. BUILD THE QUERY
337
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
337
my $lang = C4::Output::getlanguagecookie($cgi);
338
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
338
339
339
sub _input_cgi_parse ($) { 
340
sub _input_cgi_parse ($) { 
340
    my @elements;
341
    my @elements;
341
- 

Return to bug 3172