- my $toindex=$scrubber->scrub($params{content});
-
- # Take 512 characters for a sample, then extend it out
- # if it stopped in the middle of a word.
- my $size=512;
- my ($sample)=substr($toindex, 0, $size);
- if (length($sample) == $size) {
- my $next=substr($toindex, $size++, 1);
- while (defined $next && $next !~ /\s/) {
- $sample.=$next;
- $next=substr($toindex, $size++, 1);
- }
+ }
+ my $toindex = defined $scrubber ? $scrubber->scrub($params{content}) : $params{content};
+
+ # Take 512 characters for a sample, then extend it out
+ # if it stopped in the middle of a word.
+ my $size=512;
+ my ($sample)=substr($toindex, 0, $size);
+ if (length($sample) == $size) {
+ my $max=length($toindex);
+ my $next;
+ while ($size < $max &&
+ ($next=substr($toindex, $size++, 1)) !~ /\s/) {
+ $sample.=$next;
+ }
+ }
+ $sample=~s/\n/ /g;
+
+ # data used by omega
+ # Decode html entities in it, since omega re-encodes them.
+ eval q{use HTML::Entities};
+ $doc->set_data(
+ "url=".urlto($params{page}, "")."\n".
+ "sample=".decode_entities($sample)."\n".
+ "caption=".decode_entities($caption)."\n".
+ "modtime=$IkiWiki::pagemtime{$params{page}}\n".
+ "size=".length($params{content})."\n"
+ );
+
+ # Index document and add terms for other metadata.
+ my $tg = Search::Xapian::TermGenerator->new();
+ if (! $stemmer) {
+ my $langcode=$ENV{LANG} || "en";
+ $langcode=~s/_.*//;
+
+ # This whitelist is here to work around a xapian bug (#486138)
+ my @whitelist=qw{da de en es fi fr hu it no pt ru ro sv tr};
+
+ if (grep { $_ eq $langcode } @whitelist) {
+ $stemmer=Search::Xapian::Stem->new($langcode);