Bump version and update Changes
[zeal.git] / t / mkindex.pl
CommitLineData
c1c9c817
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use Cwd qw/getcwd/;
6use File::Find;
7use File::Spec::Functions qw/abs2rel/;
8use Zeal::Docset;
9
10sub 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
34mkindex $_ for <ds/*>
This page took 0.011366 seconds and 4 git commands to generate.