#!/bin/sh
#
# Copyright (C) 1997 - 2001 Loic Dachary
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

. test_functions

if [ "$mifluz" != "yes" ]
then
    echo "SKIP: index_test needs mifluz library"
    exit 77
fi

export LTDL_LIBRARY_PATH=${srcdir}/../hooks/.libs

samples_base=http://localhost:7400/
samples=http://localhost:7400/index

Iinsert() {
init_sql
#
# Only one URL is crawled and it contains only a few words
#
$crawler -hook hooksmifluz -base $testdb -robot_delay 0 -- $samples/simple.html
htdb_dump -W -z -p -s dict inverted 2>&1 | sed -n 's/.*\(fleur\).*/\1/p'
}

Idelete() {
init_sql
#
# Only one URL is crawled and it contains only a few words
#
$crawler -hook hooksmifluz -base $testdb -robot_delay 0 -- $samples/simple.html
htdb_dump -W -z -p -s dict inverted 2>&1 | sed -n 's/.*\(fleur\).*/\1/p'
mv htdocs/index/simple.html htdocs/index/simple.html.bak
$crawler -noheuristics -hook hooksmifluz -base $testdb -- $samples/simple.html
mv htdocs/index/simple.html.bak htdocs/index/simple.html
htdb_dump -W -z -p -s dict inverted
}

Iupdate() {
init_sql
#
# Only one URL is crawled and it contains only a few words
#
$crawler -hook hooksmifluz -base $testdb -robot_delay 0 -- $samples/simple.html
htdb_dump -W -z -p -s dict inverted 2>&1 | sed -n 's/.*\(fleur\|chaussure\).*/\1/p'
mv htdocs/index/simple.html htdocs/index/simple.html.bak
cp htdocs/index/simple.html.changed htdocs/index/simple.html
$crawler -noheuristics -hook hooksmifluz -base $testdb -- $samples/simple.html
mv htdocs/index/simple.html.bak htdocs/index/simple.html
htdb_dump -W -z -p -s dict inverted 2>&1 | sed -n 's/.*\(fleur\|chaussure\).*/\1/p'
}

Irebuild() {
init_sql
$crawler -verbose_hooks -hook hooksmifluz -base $testdb -robot_delay 0 -- $samples/simple.html
( htdb_dump -W -z -p -s index inverted ; htdb_dump -W -z -p -s dict inverted ) > /tmp/1$$
$crawler -verbose_hooks -hook hooksmifluz -base $testdb -rebuild
( htdb_dump -W -z -p -s index inverted ; htdb_dump -W -z -p -s dict inverted ) > /tmp/2$$
diff /tmp/[12]$$
rm -f /tmp/[12]$$
}

# test the where_url command-line argument
# permits to specifiy a set of urls to rebuild
Irebuild_where() {
init_sql
$crawler -base $testdb -robot_delay 0 -- $samples_base/langrec.html 
$crawler -base $testdb -robot_delay 0 -- $samples_base/big.html
$crawler -verbose_hooks -hook hooksmifluz -base $testdb -robot_delay 0 -rebuild -where_url "url regexp 'big'" 
}

Iiso8859() {
init_sql
$crawler -verbose_hooks -hook hooksmifluz -base $testdb -robot_delay 0 -- $samples/iso8859-1.html
htdb_dump -W -z -p -s dict inverted #2>&1 | sed -n 's/.*\(seance\).*/\1/p'
}


testing ${*:-"Iinsert Irebuild Idelete Iupdate Irebuild_where"}
