Index: /trunk/gsdl/perllib/classify/phind.pm
===================================================================
--- /trunk/gsdl/perllib/classify/phind.pm	(revision 1802)
+++ /trunk/gsdl/perllib/classify/phind.pm	(revision 1803)
@@ -30,7 +30,11 @@
 #
 # options are:
-#   title=Title           The title field for this classification 
+#   button=Name           The label for the classifiers button in the
+#                         navigation bar (defaults to "Topic").
+#   title=Title           The metadata field used to describe each document
+#                         (defaults to "Title").
 #   text=fields           The text used to build the phrase hierarchy
-#   phindexdir=directory  Location of phind index files
+#                         (defaults to "section:Title,section:text").
+#   phinddir=directory  Location of phind index files
 #   verbosity=num         Control amount of output
 #   untidy=true           Do not clean up intermediate files
@@ -41,8 +45,9 @@
 # How a classifier works.  
 #
-# When a classifier is requested in the collect.cfg file, buildcol creates a
-# new classifier object (such as the one defined in theis file) and later
-# passes each document object to the classifier in turn.  Four functions are
-# used:
+# For each classifier requested in the collect.cfg file, buildcol.pl creates
+# a new classifier object (such as the one defined in theis file) and later
+# passes each document object to the classifier in turn for classification.
+#
+# Four functions are used:
 #
 # 1. "new" is called before the documents are processed to set up the
@@ -51,5 +56,5 @@
 # 2. "init" is called after buildcol.pl has created the indexes etc but
 #    before the documents are classified in order that the classifier might
-#    set any varioables it requiers, etc.
+#    set any variables it requires, etc.
 #
 # 3. "classify" is called once for each document object.  The classifier
@@ -136,13 +141,15 @@
 	exit(1);
     }
-	
 
     # The installation appears OK - set up the classifier
     my $collection = $ENV{'GSDLCOLLECTION'};
-    my $phindexdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"phindex");
     my $language = "english";
 
-    my $title = "Topic";
+    my $button = "Phrase";
+    my $title = "Title";
     my $indexes = "section:Title,section:text";
+
+    my $builddir = "";
+    my $phinddir = "";
 
     my $suffixmode = 1;
@@ -154,4 +161,6 @@
     # parse the options
     foreach $option (@options) {
+
+	print STDERR "option: $option\n";
 
 	if ($option =~ /^text=(.*)$/i) {
@@ -159,6 +168,10 @@
 	} elsif ($option =~ /^title=(.*)$/i) {
 	    $title = $1;
-	} elsif ($option =~ /^phindexdir=(.*)$/i) {
-	    $phindexdir = $1;
+	} elsif ($option =~ /^button=(.*)$/i) {
+	    $button = $1;
+	} elsif ($option =~ /^builddir=(.*)$/i) {
+	    $builddir = $1;
+	} elsif ($option =~ /^phinddir=(.*)$/i) {
+	    $phinddir = $1;
 	} elsif ($option =~ /^suffixsize=(.*)$/i) {
 	    $suffixsize = $1;
@@ -172,14 +185,13 @@
     }
 
-
+    # classifier information
     $self->{'collection'} = $collection;
-    $self->{'title'} = $title;
+    $self->{'titlefield'} = $title;
+    $self->{'buttonname'} = $button;
     $self->{'indexes'} = $indexes;
 
+    # phrase extraction options
     $self->{'suffixmode'} = $suffixmode;
     $self->{'suffixsize'} = $suffixsize;
-
-    $self->{'verbosity'} = $verbosity;
-    $self->{'untidy'} = $untidy;
 
     # limit languages
@@ -188,10 +200,19 @@
     $self->{'delimiter'} = $delimiter;
 
-    # reset phindex directory
-    if (-e "$phindexdir") {
-	&util::rm_r("$phindexdir");
-    }
-    &util::mk_dir("$phindexdir");
-    $self->{'phindexdir'} = $phindexdir;
+    # build directory
+    if (!$builddir) {
+	$builddir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "building");
+    }
+    $self->{'builddir'} = $builddir;
+
+    # phind directory
+    if (!$phinddir) {
+        $phinddir = &util::filename_cat($builddir, "phind");
+    }
+    $self->{'phinddir'} = $phinddir;
+
+    # debugging levels
+    $self->{'verbosity'} = $verbosity;
+    $self->{'untidy'} = $untidy;
 
     return bless $self, $class;
@@ -204,13 +225,22 @@
     my $self = shift (@_);
 
+    # ensure we have a build directory
+    my $builddir = $self->{'builddir'};
+    die unless (-e "$builddir");
+
+    # create phind directory
+    my $phinddir = $self->{'phinddir'};
+    if (-e "$phinddir") {
+	&util::rm_r("$phinddir");
+    }
+    &util::mk_dir("$phinddir");
+
     # open filehandles for documents and text
-    my $phindexdir = $self->{'phindexdir'};
-
-    my $clausefile =  &util::filename_cat("$phindexdir", "clauses");
+    my $clausefile =  &util::filename_cat("$phinddir", "clauses");
     &util::rm($clausefile) if (-e $clausefile);
     open(TEXT, ">$clausefile") || die "Cannot open $clausefile: $!";
     $self->{'txthandle'} = TEXT;
 
-    my $docfile = &util::filename_cat("$phindexdir", "docs.txt");
+    my $docfile = &util::filename_cat("$phinddir", "docs.txt");
     &util::rm($docfile) if (-e $docfile);
     open(DOCS, ">$docfile") || die "Cannot open $docfile: $!";
@@ -232,5 +262,7 @@
     my $top_section = $doc_obj->get_top_section();
 
-    my $title = $doc_obj->get_metadata_element ($top_section, "Title");
+    my $titlefield = $self->{'titlefield'};
+    
+    my $title = $doc_obj->get_metadata_element ($top_section, $titlefield);
     print "process: $title\n" if ($verbosity > 2);
 
@@ -316,8 +348,8 @@
 #
 # When get_classify_info is called, the clauses and docs.txt files have
-# already been constructed in the phindex directory.  This function will
+# already been constructed in the phind directory.  This function will
 # translate them into compressed, indexed MGPP files that can be read by
 # the phindcgi script.  It will also register our classifier so that it
-# shows up in thenavigation bar.
+# shows up in the navigation bar.
 
 sub get_classify_info {
@@ -325,5 +357,5 @@
 
     my $verbosity = $self->{'verbosity'};
-    my $phindexdir = $self->{'phindexdir'};
+    my $phinddir = $self->{'phinddir'};
     my $language = "english";
     
@@ -340,13 +372,13 @@
     # from the clauses file
     print "\nExtracting vocabulary and statistics\n" if $verbosity;
-    &extract_vocabulary($phindexdir, $language, $verbosity);
-
-    # Use the suffix program to generate the phindex/phrases file
+    &extract_vocabulary($phinddir, $language, $verbosity);
+
+    # Use the suffix program to generate the phind/phrases file
     print "\nExtracting phrases from processed text (with suffix)\n" if $verbosity;
-    &execute("suffix $phindexdir $suffixsize $suffixmode", $verbosity);
-
-    # Create the phrase file and put phrase numbers in phindex/phrases
+    &execute("suffix $phinddir $suffixsize $suffixmode", $verbosity);
+
+    # Create the phrase file and put phrase numbers in phind/phrases
     print "\nSorting and Renumbering phrases for input to mgpp\n" if $verbosity;
-    &renumber_phrases("$phindexdir", $verbosity);
+    &renumber_phrases("$phinddir", $verbosity);
     
     # Create the mg phrase database
@@ -361,35 +393,35 @@
 
     print "\nCreating phrase databases\n";
-    my $mg_input = &util::filename_cat($phindexdir, "pdata.txt");
+    my $mg_input = &util::filename_cat($phinddir, "pdata.txt");
     my $mg_stem = "pdata";
 
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T1 $mg_input", $verbosity);
-    &execute("$mg_compression_dict -d $phindexdir -f $mg_stem", $verbosity);
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T2 $mg_input", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T1 $mg_input", $verbosity);
+    &execute("$mg_compression_dict -d $phinddir -f $mg_stem", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T2 $mg_input", $verbosity);
 
     # create the mg index of words
     print "\nCreating word-level search indexes\n";
-    $mg_input = &util::filename_cat($phindexdir, "pword.txt");
+    $mg_input = &util::filename_cat($phinddir, "pword.txt");
     $mg_stem = "pword";
 
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T1 -I1 $mg_input", $verbosity);
-    &execute("$mg_compression_dict -d $phindexdir -f $mg_stem", $verbosity);
-    &execute("$mg_perf_hash_build -d $phindexdir -f $mg_stem", $verbosity);
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T2 -I2 $mg_input", $verbosity);
-    &execute("$mg_weights_build -d $phindexdir -f $mg_stem", $verbosity);
-    &execute("$mg_invf_dict -d $phindexdir -f $mg_stem", $verbosity);
-
-    &execute("$mg_stem_idx -d $phindexdir -f $mg_stem -s 1", $verbosity);
-    &execute("$mg_stem_idx -d $phindexdir -f $mg_stem -s 2", $verbosity);
-    &execute("$mg_stem_idx -d $phindexdir -f $mg_stem -s 3", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T1 -I1 $mg_input", $verbosity);
+    &execute("$mg_compression_dict -d $phinddir -f $mg_stem", $verbosity);
+    &execute("$mg_perf_hash_build -d $phinddir -f $mg_stem", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T2 -I2 $mg_input", $verbosity);
+    &execute("$mg_weights_build -d $phinddir -f $mg_stem", $verbosity);
+    &execute("$mg_invf_dict -d $phinddir -f $mg_stem", $verbosity);
+
+    &execute("$mg_stem_idx -d $phinddir -f $mg_stem -s 1", $verbosity);
+    &execute("$mg_stem_idx -d $phinddir -f $mg_stem -s 2", $verbosity);
+    &execute("$mg_stem_idx -d $phinddir -f $mg_stem -s 3", $verbosity);
 
     # create the mg document information database
     print "\nCreating document information databases\n";
-    $mg_input = &util::filename_cat($phindexdir, "docs.txt");
+    $mg_input = &util::filename_cat($phinddir, "docs.txt");
     $mg_stem = "docs";
 
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T1 $mg_input", $verbosity);
-    &execute("$mg_compression_dict -d $phindexdir -f $mg_stem", $verbosity);
-    &execute("$mg_passes -d $phindexdir -f $mg_stem -T2 $mg_input", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T1 $mg_input", $verbosity);
+    &execute("$mg_compression_dict -d $phinddir -f $mg_stem", $verbosity);
+    &execute("$mg_passes -d $phinddir -f $mg_stem -T2 $mg_input", $verbosity);
 
 
@@ -397,11 +429,11 @@
     if (!$untidy) {
 	print "\nCleaning up\n" if ($verbosity > 2);
-	&util::rm("$phindexdir/clauses", "$phindexdir/clauses.numbers", 
-		  "$phindexdir/clauses.vocab", "$phindexdir/clauses.stats", 
-		  "$phindexdir/phrases", "$phindexdir/docs.txt",
-		  "$phindexdir/pdata.txt", "$phindexdir/pword.txt");
+	&util::rm("$phinddir/clauses", "$phinddir/clauses.numbers", 
+		  "$phinddir/clauses.vocab", "$phinddir/clauses.stats", 
+		  "$phinddir/phrases", "$phinddir/docs.txt",
+		  "$phinddir/pdata.txt", "$phinddir/pword.txt");
 	my $outfile = 1;
-	while (-e "$phindexdir/outPhrase.$outfile") {
-	    &util::rm("$phindexdir/outPhrase.$outfile");
+	while (-e "$phinddir/outPhrase.$outfile") {
+	    &util::rm("$phinddir/outPhrase.$outfile");
 	    $outfile++;
 	}
@@ -415,5 +447,5 @@
     my %classifyinfo = ('thistype'=>'Invisible',
 			'childtype'=>'Phind',
-			'Title'=>$self->{'title'},
+			'Title'=>$self->{'buttonname'},
 			'contains'=>[]);
     
@@ -531,5 +563,5 @@
 
 sub extract_vocabulary {
-    my ($phindex_dir, $language, $verbosity) = @_;
+    my ($phind_dir, $language, $verbosity) = @_;
 
     my ($w, $l, $line, $word);
@@ -575,5 +607,5 @@
 
     # Read words in the text and count occurences
-    open(TXT, "<$phindex_dir/clauses");
+    open(TXT, "<$phind_dir/clauses");
     my @words;
     
@@ -684,6 +716,6 @@
 
     # Outut the words
-    print "Saving vocabulary in $phindex_dir/clauses.vocab\n" if ($verbosity > 1);
-    open(VOC, ">$phindex_dir/clauses.vocab");
+    print "Saving vocabulary in $phind_dir/clauses.vocab\n" if ($verbosity > 1);
+    open(VOC, ">$phind_dir/clauses.vocab");
 
     for (my $i = 1; $i < $nextsymbol; $i++) {
@@ -697,8 +729,8 @@
 
     # Output statistics about the vocablary
-    print "Saving statistics in $phindex_dir/clauses.stats\n" if ($verbosity > 1);
-    &util::rm("$phindex_dir/clauses.stats") if (-e "$phindex_dir/clauses.stats");
-    open(STAT, ">$phindex_dir/clauses.stats")
-	|| die "Cannot open $phindex_dir/clauses.stats: $!";
+    print "Saving statistics in $phind_dir/clauses.stats\n" if ($verbosity > 1);
+    &util::rm("$phind_dir/clauses.stats") if (-e "$phind_dir/clauses.stats");
+    open(STAT, ">$phind_dir/clauses.stats")
+	|| die "Cannot open $phind_dir/clauses.stats: $!";
 
     print STAT "first_delimiter $first_delimiter\n";
@@ -724,8 +756,8 @@
 
     # Save text as symbol numbers
-    print "Saving text as numbers in $phindex_dir/clauses.numbers\n" if ($verbosity > 1);
-    
-    open(TXT, "<$phindex_dir/clauses");
-    open(NUM, ">$phindex_dir/clauses.numbers");
+    print "Saving text as numbers in $phind_dir/clauses.numbers\n" if ($verbosity > 1);
+    
+    open(TXT, "<$phind_dir/clauses");
+    open(NUM, ">$phind_dir/clauses.numbers");
     
     $phrasedelimiter = $symbol{lc($senlimit)};
@@ -763,10 +795,10 @@
 
 sub renumber_phrases {
-    my ($phindex_dir, $verbosity) = @_;
+    my ($phind_dir, $verbosity) = @_;
 
     # Sort the phrases into order of increasing frequency
     # This means the expansions will be sorted correctly later on.
     print "Sorting phrases into freq order\n" if ($verbosity);
-    system("sort -rnt ':' +2 -o $phindex_dir/phrases $phindex_dir/phrases");
+    system("sort -rnt ':' +2 -o $phind_dir/phrases $phind_dir/phrases");
 
     my @symbol;
@@ -774,6 +806,6 @@
     # Read the vocabulary
     print "Reading the vocabulary\n" if ($verbosity);
-    open(V, "<$phindex_dir/clauses.vocab")
-	|| die "Cannot open $phindex_dir/clauses.vocab: $!";
+    open(V, "<$phind_dir/clauses.vocab")
+	|| die "Cannot open $phind_dir/clauses.vocab: $!";
     
     my $i = 1;
@@ -799,5 +831,5 @@
     my ($line);
     
-    open(IN, "<$phindex_dir/phrases");
+    open(IN, "<$phind_dir/phrases");
     while(<IN>) {
 	
@@ -818,7 +850,7 @@
     print "Format phrase data for MGPP\n" if ($verbosity);
     
-    open(IN, "<$phindex_dir/phrases");
-    open(DATA, ">$phindex_dir/pdata.txt");
-    open(IDX, ">$phindex_dir/pword.txt");
+    open(IN, "<$phind_dir/phrases");
+    open(DATA, ">$phind_dir/pdata.txt");
+    open(IDX, ">$phind_dir/pword.txt");
     
     my ($key, $tf, $num, $countexp, $expansions, $countdocs, $documents, $text, $word);
Index: /trunk/gsdl/perllib/mgbuilder.pm
===================================================================
--- /trunk/gsdl/perllib/mgbuilder.pm	(revision 1802)
+++ /trunk/gsdl/perllib/mgbuilder.pm	(revision 1803)
@@ -139,5 +139,5 @@
     
     # load all the classifiers
-    $self->{'classifiers'} = &classify::load_classifiers ($classifiers, $outhandle);
+    $self->{'classifiers'} = &classify::load_classifiers ($classifiers, $build_dir, $outhandle);
 
     # load up any dontgdbm fields
Index: /trunk/gsdl/src/phind/host/phindcgi.cpp
===================================================================
--- /trunk/gsdl/src/phind/host/phindcgi.cpp	(revision 1802)
+++ /trunk/gsdl/src/phind/host/phindcgi.cpp	(revision 1803)
@@ -144,5 +144,5 @@
   strcat(basepath, "/collect/");
   strcat(basepath, collection);
-  strcat(basepath, "/phindex");
+  strcat(basepath, "/index/phind");
 
   // If we don't know the phrase number, look itup
@@ -720,5 +720,5 @@
   
   // mode 1 = casefolded, unstemmed search
-  QueryNode *queryTree = ParseQuery(query, 1);
+  QueryNode *queryTree = ParseQuery(query, 1, 1);
 
   // cout << "-- query --" << endl;
