NAME

Search::Kinosearch::Query - create queries to feed to KSearch

DEPRECATED

Search::Kinosearch has been superseded by KinoSearch. Please use the new version.

SYNOPSIS

my $query = Search::Kinosearch::Query->new(
    -string     => 'this AND NOT (that OR "the other thing")',
    -lowercase  => 1,
    -tokenize   => 1,
    -stem       => 1,
    );
$ksearch->add_query( $query );
$ksearch->process;

while (my $results = $ksearch->fetch_result_hashref) {
    print "$results->{title}\n";
}

DESCRIPTION

Query syntax

Operators, in descending order of precedence:

"double quotes"

If phrases are enabled, then passages surrounded by double quotes are evaluated as phrases. If the closing quote is omitted, the phrase is defined as closed by the end of the query string. No other operators are evaluated within a phrase.

prepended +plus and -minus

Require or negate an item. It is possible to require or negate a phrase: 'foo -"bar baz"' ... or a parenthetical group: 'foo +(bar baz)'.

(parentheses)

Bind items into logical groups.

x AND y, x OR y, x AND NOT y

These three operators, whose primary functions should be obvious, have the effect of grouping the items on either side of them, as if surrounded by parentheses.

Note that Kinosearch's "boolean" queries do not support a full complement of boolean operators. For XOR and NAND, that's because so few people would ever use them. More subtly, NOT is only available as half of AND NOT, because in the vast majority of cases it would undesirable for the query "NOT freekezoidzzzzz" to return every document in the kindex. Prepended -minuses are treated the same way: '-foo' on its own returns no documents. In both cases the negated set must be subtracted from something in order to have any effect: 'foo AND NOT bar', 'foo -bar'. Isolating a term with a prepended -minus inside parentheses turns it into a no-op: 'foo (-bar)' returns all docs containing 'foo', including those that contain 'bar'.

CONSTRUCTOR

new()

my $query = Search::Kinosearch::Query->new(
    -string     => $query_string,   # Required.
    -lowercase  => 1,               # Default: 0
    -tokenize   => 1,               # Default: 0
    -stem       => 1,               # Default: 0
    -required   => 1,               # Default: 0
    -negated    => 0,               # Default: 0
    -fields     => {                # Default: use aggregate score
                       title    => 3,
                       bodytext => 1, 
                   },
    );

Add a query to the KSearch object.

-string

The string to be matched against.

-lowercase

Convert query to lower case.

-tokenize

Tokenize the query.

-stem

Stem terms within the query.

-required

Return only results which match this query.

-negated

Return only results which do NOT match this query.

-fields

Specify fields to search against in the kindex. Must be supplied as a hash, with the fields to be searched as keys and the weight that those fields are to be given as values.

TO DO

  • Consider whether it might be better to remove parameters such as -allow_boolean from KSearch, instead creating subclasses like Search::Kinosearch::Query::Boolean.

  • Implement subclasses.

SEE ALSO

AUTHOR

Marvin Humphrey <marvin at rectangular dot com>

COPYRIGHT

Copyright (c) 2005 Marvin Humphrey. All rights reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.