---
name: "KinoSearch::QueryParser::QueryParser"
section: "3pm"
platform: "linux"
package: "libkinosearch-perl"
version: "0.165-2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/KinoSearch::QueryParser::QueryParser"
---

# KinoSearch::QueryParser::QueryParser(3pm)

transform a string into a Query object

## NAME

KinoSearch::QueryParser::QueryParser - transform a string into a Query object

## SYNOPSIS

```
    my $query_parser = KinoSearch::QueryParser::QueryParser->new(
        analyzer => $analyzer,
        fields   => [ 'bodytext' ],
    );
    my $query = $query_parser->parse( $query_string );
    my $hits  = $searcher->search( query => $query );
```

## DESCRIPTION

The QueryParser accepts search strings as input and produces Query objects, suitable for feeding into KinoSearch::Searcher.

### Syntax

The following constructs are recognized by QueryParser.

- •

  Boolean operators 'AND', 'OR', and 'AND NOT'.

- •

  Prepented +plus and -minus, indicating that the labeled entity should be either required or forbidden -- be it a single word, a phrase, or a parenthetical group.

- •

  Logical groups, delimited by parentheses.

- •

  Phrases, delimited by double quotes.

- •

  Field-specific terms, in the form of `"fieldname:termtext"`.  (The field specified by fieldname will be used instead of the QueryParser's default fields).

  A field can also be given to a logical group, in which case it is the same as if the field had been prepended onto every term in the group.  For example: `"foo:(bar baz)"` is the same as `"foo:bar foo:baz"`.

## METHODS

### new

```
    my $query_parser = KinoSearch::QueryParser::QueryParser->new(
        analyzer       => $analyzer,       # required
        fields         => [ 'bodytext' ],  # required
        default_boolop => 'AND',           # default: 'OR'
    );
```

Constructor.  Takes hash-style parameters:

- •

  **analyzer** - An object which subclasses KinoSearch::Analysis::Analyzer.  This **must** be identical to the Analyzer used at index-time, or the results won't match up.

- •

  **fields** - the names of the fields which will be searched against.  Must be supplied as an arrayref.

- •

  **default\_field** - deprecated. Use `"fields"` instead.

- •

  **default\_boolop** - two possible values: 'AND' and 'OR'.  The default is 'OR', which means: return documents which match any of the query terms.  If you want only documents which match all of the query terms, set this to 'AND'.

### parse

```
    my $query = $query_parser->parse( $query_string );
```

Turn a query string into a Query object.  Depending on the contents of the query string, the returned object could be any one of several subclasses of KinoSearch::Search::Query.

## COPYRIGHT

Copyright 2005-2009 Marvin Humphrey

## LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.165.
