#!perl -w
# Copyright (C) 2020 all contributors
# License: AGPL-3.0+
# Basic tool to create a Xapian search index for a public-inbox.
use strict;
use v5.10.1;
use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
my $help = < -1, compact => 0, max_size => undef, fsync => 1 };
GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i
fsync|sync!
indexlevel|index-level|L=s max_size|max-size=s
batch_size|batch-size=s
skip-docdata all help|h))
or die $help;
if ($opt->{help}) { print $help; exit 0 };
die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
# require lazily to speed up --help
my $eidx_dir = shift(@ARGV) // die "E: $help";
require PublicInbox::Admin;
my $cfg = PublicInbox::Config->new;
my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
PublicInbox::Admin::require_or_die(qw(-search));
require PublicInbox::ExtSearchIdx;
my $eidx = PublicInbox::ExtSearchIdx->new($eidx_dir, $opt);
$eidx->attach_inbox($_) for @ibxs;
$eidx->eidx_sync($opt);