Changeset 2591 for trunk/doc/misc/buildIndex.pl
- Timestamp:
- Dec 1, 2004, 12:34:23 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/doc/misc/buildIndex.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/misc/buildIndex.pl
r2471 r2591 5 5 # $Id: buildIndex.pl,v 1.1 2004/04/20 22:16:17 jhoblitt Exp $ 6 6 7 use 5.008; 8 7 9 use strict; 8 10 use warnings; 9 11 10 use vars qw( $VERSION ); 11 $VERSION = '0.01'; 12 our $VERSION = '0.01'; 12 13 13 14 use File::Basename qw(); … … 21 22 use Pod::Usage qw( pod2usage ); 22 23 23 my ($verbose, $help, $path, $index _dir);24 my ($verbose, $help, $path, $indexDir); 24 25 GetOptions( 25 26 'verbose' => \$verbose, 26 27 'path=s' => \$path, 27 'index=s' => \$index _dir,28 'index=s' => \$indexDir, 28 29 ) 29 30 or pod2usage(2); … … 32 33 pod2usage(-msg => "Required option: --path|-p", -exitval => 2) unless $path; 33 34 34 $index _dir = $path . "/.index" unless defined $index_dir;35 $indexDir = $path . "/.index" unless defined $indexDir; 35 36 36 37 ##my $stripper = HTML::Strip->new; 37 38 38 39 my $writer = Plucene::Index::Writer->new( 39 $index _dir,40 $indexDir, 40 41 Plucene::Plugin::Analyzer::PorterAnalyzer->new(), 41 42 1 # Create the index from scratch … … 44 45 my $doc = Plucene::Document->new; 45 46 46 foreach my $file _name (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) {47 print "indexing: $file _name\n" if $verbose;48 $writer->add_document(parse _mhonarc_html($file_name));47 foreach my $filename (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) { 48 print "indexing: $filename\n" if $verbose; 49 $writer->add_document(parseMhonarcHtml($filename)); 49 50 } 50 51 51 sub parse _mhonarc_html52 sub parseMhonarcHtml 52 53 { 53 my $file _name = shift;54 55 my $tree = HTML::TreeBuilder->new_from_file($file _name);54 my $filename = shift; 55 56 my $tree = HTML::TreeBuilder->new_from_file($filename); 56 57 my $doc = Plucene::Document->new; 57 58 58 $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($file _name),));59 $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($filename),)); 59 60 60 61 # get the header values for to, cc, from, date, and subject 61 62 62 63 # find the <div> tag labeled header 63 my $header _tag = $tree->look_down(_tag => "div", id => "header");64 my $headerTag = $tree->look_down(_tag => "div", id => "header"); 64 65 65 66 my %headers; 66 67 67 foreach my $row _node ($header_tag->look_down(_tag => "tr")) {68 foreach my $rowNode ($headerTag->look_down(_tag => "tr")) { 68 69 69 70 # process each row of the header 70 71 71 72 # get name of header field 72 my $name _node = $row_node->look_down(_tag => "td");73 my $name = lc($name _node->look_down(_tag => "em")->as_text);74 $name _node->delete;73 my $nameNode = $rowNode->look_down(_tag => "td"); 74 my $name = lc($nameNode->look_down(_tag => "em")->as_text); 75 $nameNode->delete; 75 76 76 77 # get content of header field 77 my $content _node = $row_node->look_down(_tag => "td");78 my $content = $content_node->as_text;78 my $contentNode = $rowNode->look_down(_tag => "td"); 79 my $content = $contentNode->as_text; 79 80 80 81 # index "cc" as part of "to" … … 90 91 91 92 # find the <div> tag labeled content 92 my $content _tag = $tree->root->look_down(_tag => "div", id => "content");93 my $contentTag = $tree->root->look_down(_tag => "div", id => "content"); 93 94 94 95 # index message body 95 96 print "\tadding to index content\n" if $verbose; 96 $doc->add(Plucene::Document::Field->UnStored(content => $content _tag->as_text));97 $doc->add(Plucene::Document::Field->UnStored(content => $contentTag->as_text)); 97 98 98 99 return $doc; … … 105 106 =head1 NAME 106 107 107 build _index.pl - generate Plucene/Lucene index of MHonarc archives108 buildIndex.pl - generate Plucene/Lucene index of MHonarc archives 108 109 109 110 =head1 SYNOPSIS 110 111 111 build _index.pl --path dir [--index dir] [--verbose]112 buildIndex.pl --path dir [--index dir] [--verbose] 112 113 113 114 or 114 115 115 build _index.pl -p dir [-i dir] [-v]116 buildIndex.pl -p dir [-i dir] [-v] 116 117 117 118 or 118 119 119 build _index.pl [--help | -h | -? | --version]120 buildIndex.pl [--help | -h | -? | --version] 120 121 121 122 =head1 DESCRIPTION … … 148 149 =back 149 150 150 =head1 DEVELOPER S151 =head1 DEVELOPER NOTES 151 152 152 153 The parser extracts the C<to>, C<cc>, C<from>, C<subject>, and C<date> headers … … 201 202 Place - Suite 330, Boston, MA 02111-1307, USA. 202 203 203 The full text of the license can be found in the L ICENSE file included with204 this module, or in the L<perlgpl> Pod as suppliedwith Perl 5.8.1 and later.204 The full text of the license can be found in the L<perlgpl> Pod as supplied 205 with Perl 5.8.1 and later. 205 206 206 207 =head1 SEE ALSO
Note:
See TracChangeset
for help on using the changeset viewer.
