The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Search::Tools - tools for building search applications

SYNOPSIS

 use Search::Tools;
 
 my $query = 'the quik brown fox';
 
 my $re = Search::Tools->regexp(query => $query);
 
 my $snipper    = Search::Tools->snipper(query => $re);
 my $hiliter    = Search::Tools->hiliter(query => $re);
 my $spellcheck = Search::Tools->spellcheck(query => $re);

 my $suggestions = $spellcheck->suggest($query);
 
 for my $s (@$suggestions)
 {
    if (! $s->{suggestions})
    {
        # $s->{word} was spelled correctly
    }
    elsif (@{ $s->{suggestions} })
    {
        print "Did you mean: " . join(' or ', @{$s->{suggestions}}) . "\n";
    }
 }

 for my $result (@search_results)
 {
    print $hiliter->light( $snipper->snip( $result->summary ) );
 }
  
 

DESCRIPTION

Search::Tools is a set of utilities for building search applications. Rather than adhering to a particular search application, the goal of Search::Tools is to provide general-purpose methods for common search application features. Think of Search::Tools like a toolbox rather than a hammer.

Examples include:

  • Parsing search queries for the meaningful keywords

  • Rich regular expressions for locating keywords in the original indexed documents

  • Contextual snippets showing query keywords

  • Highlighting of keywords in context

  • Spell check keywords and suggestions of alternate spellings.

Search::Tools is derived from some of the features in HTML::HiLiter and SWISH::HiLiter, but has been re-written with an eye to accomodating more general purpose features.

REQUIREMENTS

Perl 5.8 or later is required. This is for full UTF-8 support.

The following CPAN modules are required:

Class::Accessor::Fast
Search::QueryParser
Text::Aspell

See also the specific module documentation for individual requirements.

METHODS

transliterate( text )

See Search::Tools::Transliterate convert().

The following convenience methods are simple class methods around the indicated module. Each of them requires a query key/value pair parameter.

regexp

snipper

hiliter

spellcheck

COMMON ACCESSORS

The following common accessors are inherited by every module in Search::Tools:

    stopwords
    wildcard
    word_characters
    ignore_first_char
    ignore_last_char
    stemmer
    phrase_delim
    ignore_case
    debug
    locale
    charset
    lang

See each module's documentation for more details.

EXAMPLES

See the tests in t/ for examples.

AUTHOR

Peter Karman perl@peknet.com

Based on the HTML::HiLiter regular expression building code, originally by the same author, copyright 2004 by Cray Inc.

Thanks to Atomic Learning www.atomiclearning.com for sponsoring the development of these modules.

COPYRIGHT

Copyright 2006 by Peter Karman. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

HTML::HiLiter, SWISH::HiLiter, Search::Tools::Keywords, Search::Tools::RegExp, Search::Tools::RegExp::Keywords, Search::Tools::RegExp::Keyword, Search::Tools::Snipper, Search::Tools::HiLiter, Search::Tools::SpellCheck