# Plucene::TestCase - Handy functions when testing Plucene - perldoc - [phpMan]

## NAME
    [Plucene::TestCase](https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3ATestCase/markdown) - Handy functions when testing Plucene

## SYNOPSIS
            use [Test::More](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AMore/markdown) tests => 10;
            use [Plucene::TestCase](https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3ATestCase/markdown);

            new_index {
                    add_document( foo => "bar" );
            };

            re_index {
                    add_document( foo => "baz" );
            }

            with_reader {
                    $READER->whatever;
            }

            my $hits = search("foo:ba*");

## EXPORTS
    $DIR
       A directory which is created for the purposes of this test, in which
       the index will be placed. It will normally be cleaned up at the end
       of the test, unless $[Plucene::TestCase::DEBUG](https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3ATestCase%3A%3ADEBUG/markdown) is set to allow you to
       peruse the entrails.

    $WRITER
       A variable holding the current "[Index::Writer](https://www.chedong.com/phpMan.php/perldoc/Index%3A%3AWriter/markdown)" object, if there is
       one.

    $READER
       A variable holding the current "[Index::Reader](https://www.chedong.com/phpMan.php/perldoc/Index%3A%3AReader/markdown)" object, if there is
       one.

    $ANALYZER
       A variable holding the class name of the desired "[Analysis::Analyzer](https://www.chedong.com/phpMan.php/perldoc/Analysis%3A%3AAnalyzer/markdown)"
       class.

    new_index BLOCK (Analyzer)
       Create a new index, and do the following stuff in the block before
       closing the index writer. $WRITER is set for the duration of the
       block.

       The optional parameter should be the class name of the analyzer to
       use; if not specified, the value from $ANALYZER, which in turn
       defaults to "[Plucene::Analysis::SimpleAnalyzer](https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3AAnalysis%3A%3ASimpleAnalyzer/markdown)", will be used.

    re_index BLOCK (Analyzer)
       Same as "new_index", but doesn't create a new index, rather re-uses
       an old one.

### add_document
       Add a new document to the index, with the given fields and values

    with_reader BLOCK
       Opens an index reader in $READER and runs the block.

    search
       Searches for the query given. If any fields are not specified, they
       will be assumed to be the default "text". Returns a
       "[Plucene::Search::Hits](https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3ASearch%3A%3AHits/markdown)" object. The value of $ANALYZER will be used
       to construct an analyzer for the query string.

## POD ERRORS
    Hey! The above document had some coding errors, which are explained
    below:

    Around line 49:
        =over without closing =back

