NAME

Search::Tools::Query - objectified string for highlighting, snipping, etc.

SYNOPSIS

use Search::Tools::QueryParser;
my $qparser  = Search::Tools::QueryParser->new;
my $query    = $qparser->parse(q(the quick color:brown "fox jumped"));
my $fields   = $query->fields; # ['color']
my $terms    = $query->terms;  # ['quick', 'brown', '"fox jumped"']
my $regex    = $query->regex_for($terms->[0]); # S::T::RegEx
my $tree     = $query->tree; # the Search::Query::Dialect tree()
print "$query\n";  # the quick color:brown "fox jumped"
print $query->str . "\n"; # same thing

DESCRIPTION

METHODS

fields

Array ref of fields from the original query string. See Search::Tools::QueryParser for controls over ignore_fields().

terms

Array ref of key words from the original query string. See Search::Tools::QueryParser for controls over ignore_fields() and tokenizing regex.

NOTE: Only positive words are extracted by QueryParser. In other words, if you search for:

foo not bar

then only foo is returned. Likewise:

+foo -bar

would return only foo.

str

The original string.

regex

The hash ref of terms to Search::Tools::RegEx objects.

dialect

The internal Search::Query::Dialect object. See tree() and str_clean() which delegate to the dialect object.

qp

The Search::Tools::QueryParser object used to generate the Query.

num_terms

Returns the number of terms().

unique_terms

Returns array ref of unique terms from query. If stemming was on in the QueryParser, all terms have already been stemmed as part of the parsing process.

num_unique_terms

Returns number of unique_terms().

phrases

Return array ref of RegEx objects for all terms where is_phrase is true.

non_phrases

Return array ref of RegEx objects for all terms where is_phrase is false.

tree

Returns the internal Search::Query::Dialect tree().

str_clean

Returns the internal Search::Query::Dialect stringify().

regex_for(term)

Returns a Search::Tools::RegEx object for term.

regexp_for

Alias for regex_for(). The author has come to prefer "regex" instead of "regexp" because it's one less keystroke.

matches_text( text )

Returns the number of matches for the query against text.

matches_html( html )

Returns the number of matches for the query against html.

terms_as_regex([treat_phrases_as_singles])

Returns all terms() as a single qr// regex, pipe-joined in a "OR" logic.

AUTHOR

Peter Karman <karman@cpan.org>

BUGS

Please report any bugs or feature requests to bug-search-tools at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Search-Tools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Search::Tools

You can also look for information at:

COPYRIGHT

Copyright 2009 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

Search::Query::Dialect