Initial commit
[zeal.git] / t / mkindex.pl
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 use Cwd qw/getcwd/;
6 use File::Find;
7 use File::Spec::Functions qw/abs2rel/;
8 use Zeal::Docset;
9
10 sub mkindex {
11 my ($root) = @_;
12 my $oldwd = getcwd;
13 unlink "$root/Contents/Resources/docSet.dsidx";
14
15 my $ds = Zeal::Docset->new($root);
16 $ds->dbh->do('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)');
17 $ds->dbh->do('CREATE UNIQUE INDEX anchor on searchIndex (name, type, path)');
18
19 chdir "$root/Contents/Resources/Documents";
20
21 find +{
22 no_chdir => 1,
23 wanted => sub {
24 return unless -f;
25 my ($name) = m/(\w+)\.html/;
26 my $path = abs2rel $_;
27 say STDERR "Adding document $name at $path";
28 $ds->dbh->do('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, \'Word\', ?)', {}, $name, $path);
29 }
30 }, '.';
31 chdir $oldwd;
32 }
33
34 mkindex $_ for <ds/*>
This page took 0.022632 seconds and 4 git commands to generate.