###########################################################################
#
# parallellucenebuilder.pm -- perl wrapper for building index with Lucene
# extended to support parallel building in terms of controlling index name
# and level built, and generating a 'recipe' for indexing (making use of
# former)
#
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the
# University of Waikato, New Zealand.
#
# Copyright (C) 2013 New Zealand Digital Library Project
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################

# @author David Bainbridge and Katherine Don, Waikato DL Research group
# @author John Rowe, DL Consulting Ltd.
# @author John Thompson, DL Consulting Ltd.
# @author John Thompson [jmt12], Waikato DL Research group

package parallellucenebuilder;

use lucenebuilder;
use parallelmgppbuilder;
use strict;

sub BEGIN
{
  @parallellucenebuilder::ISA = ('lucenebuilder', 'parallelmgppbuilder');
}

# /** @function new()
#  */
sub new
{
  my $class = shift(@_);
  my $self = new lucenebuilder(@_);
  return bless($self, $class);
}
# /** new() **/

# /** @function prepareIndexRecipe()
#  * The three main 'modes' in Lucene builds are completely independent, while
#  * index building can be further split by level
#  * @param $self
#  * @param $collection
#  * @param $recipe a reference to an array of recipe 'steps'
#  * @author jmt12
#  */
sub prepareIndexRecipe
{
  my ($self, $collection, $recipe) = @_;
  my $outhandle = $self->{'outhandle'};
  my $verbosity = $self->{'verbosity'};
  # 1. Compressing the text
  push(@{$recipe}, {'command'=>'buildcol.pl -keepold -verbosity ' . $verbosity . ' -mode compress_text ' . $collection});
  # 2. Info database building
  push(@{$recipe}, {'command'=>'buildcol.pl -keepold -verbosity ' . $verbosity . ' -mode infodb ' . $collection});
  # 3. Now one command each for each level of index required
  foreach my $level (keys %{$self->{'levels'}})
  {
    push(@{$recipe}, {'command'=>'buildcol.pl -keepold -verbosity ' . $verbosity . ' -mode build_index -indexlevel ' . $level . ' ' . $collection});
  }
  # Complete!
}
# /** prepareIndexRecipe() **/

1;


