]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-extindex
extindex: remove skip-docdata option
[public-inbox.git] / script / public-inbox-extindex
1 #!perl -w
2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Basic tool to create a Xapian search index for a public-inbox.
5 use strict;
6 use v5.10.1;
7 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
8 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
9 usage: public-inbox-extindex [options] EXTINDEX_DIR [INBOX_DIR]
10
11   Create and update external (detached) search indices
12
13   --no-fsync          speed up indexing, risk corruption on power outage
14   -L LEVEL            `medium', or `full' (default: full)
15   --all               index all configured inboxes
16   --jobs=NUM          set or disable parallelization (NUM=0)
17   --batch-size=BYTES  flush changes to OS after a given number of bytes
18   --max-size=BYTES    do not index messages larger than the given size
19   --verbose | -v      increase verbosity (may be repeated)
20
21 BYTES may use `k', `m', and `g' suffixes (e.g. `10m' for 10 megabytes)
22 See public-inbox-extindex(1) man page for full documentation.
23 EOF
24 my $opt = { quiet => -1, compact => 0, max_size => undef, fsync => 1 };
25 GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i
26                 fsync|sync!
27                 indexlevel|index-level|L=s max_size|max-size=s
28                 batch_size|batch-size=s
29                 all help|h))
30         or die $help;
31 if ($opt->{help}) { print $help; exit 0 };
32 die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
33
34 # require lazily to speed up --help
35 my $eidx_dir = shift(@ARGV) // die "E: $help";
36 local $SIG{USR1} = 'IGNORE'; # to be overridden in eidx_sync
37 require PublicInbox::Admin;
38 my $cfg = PublicInbox::Config->new;
39 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
40 PublicInbox::Admin::require_or_die(qw(-search));
41 PublicInbox::Admin::progress_prepare($opt);
42 my $env = PublicInbox::Admin::index_prepare($opt, $cfg);
43 local %ENV = (%ENV, %$env) if $env;
44 require PublicInbox::ExtSearchIdx;
45 my $eidx = PublicInbox::ExtSearchIdx->new($eidx_dir, $opt);
46 $eidx->attach_inbox($_) for @ibxs;
47 $eidx->eidx_sync($opt);