package C4::Biblio;
# $Id$
# $Log$
+# Revision 1.14 2002/10/03 11:28:18 tipaul
+# Extending Context.pm to add stopword management and using it in MARC-API.
+# First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
+#
# Revision 1.13 2002/10/02 16:26:44 tipaul
# road to 1.3.1
#
$sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
my @words = split / /,$sentence;
# build stopword list
- my $sth2 =$dbh->prepare("select word from stopwords");
- $sth2->execute;
- my $stopwords;
- my $stopword;
- while(($stopword) = $sth2->fetchrow_array) {
- $stopwords->{$stopword} = $stopword;
- }
+# my $sth2 =$dbh->prepare("select word from stopwords");
+# $sth2->execute;
+# my $stopwords;
+# my $stopword;
+# while(($stopword) = $sth2->fetchrow_array) {
+# $stopwords->{$stopword} = $stopword;
+# }
+ my $stopwords= C4::Context->stopwords;
my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
values (?,?,?,?,?,?,soundex(?))");
foreach my $word (@words) {
return undef if !defined($self->{"config"});
$self->{"dbh"} = undef; # Database handle
+ $self->{"stopwords"} = undef; # stopwords list
bless $self, $class;
return $self;
# return something, then this function should, too.
}
+=item stopwords
+
+ $dbh = C4::Context->stopwords;
+
+Returns a hash with stopwords.
+
+This hash is cached for future use: if you call
+C<C4::Context-E<gt>stopwords> twice, you will get the same hash without real DB access
+
+=cut
+#'
+sub stopwords
+{
+ my $retval = {};
+
+ # If the hash already exists, return it.
+ return $context->{"stopwords"} if defined($context->{"stopwords"});
+
+ # No hash. Create one.
+ $context->{"stopwords"} = &_new_stopwords();
+
+ return $context->{"stopwords"};
+}
+
+# _new_stopwords
+# Internal helper function (not a method!). This creates a new
+# hash with stopwords
+sub _new_stopwords
+{
+ my $dbh = &dbh;
+ my $stopwordlist;
+ my $sth = $dbh->prepare("select word from stopwords");
+ $sth->execute;
+ while (my $stopword = $sth->fetchrow_array) {
+ my $retval = {};
+ $stopwordlist->{$stopword} = uc($stopword);
+ }
+ return $stopwordlist;
+# my $db_driver = $context->{"config"}{"db_scheme"} || "mysql";
+# my $db_name = $context->{"config"}{"database"};
+# my $db_host = $context->{"config"}{"hostname"};
+# my $db_user = $context->{"config"}{"user"};
+# my $db_passwd = $context->{"config"}{"pass"};
+
+# return DBI->connect("DBI:$db_driver:$db_name:$db_host",
+# $db_user, $db_passwd);
+}
+
1;
__END__
=back