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::Xapian::QueryParser - Parse a query string into a Query object

DESCRIPTION

This module turns a human readable string into something Xapian can understand. The syntax supported is designed to be similar to other web based search engines, so that users familiar with them don't have to learn a whole new syntax.

SYNOPSIS

  use Search::Xapian qw/:standard/;

  my $qp = new Search::Xapian::QueryParser( [$database] );
  $qp->set_stemming_options("english",1); # Replace 1 with 0 if you want to disable stemming
  $qp->set_default_op(OP_AND);

  $database->enquire($qp->parse_query('a word OR two NEAR "a phrase" NOT (too difficult) +eh'));
 

METHODS

new <database>

QueryParser constructor.

set_stemming_options <language> <enabled>

Set language for stemming, and weither it's going to be used at all enable can be 1 or 0.

Currently supported options for language: danish, dutch, english, finnish, french, german, italian, norwegian, portuguese, russian, spanish, and swedish

set_default_op <operator>

Set default operator for joining elements. Can be one of OP_AND, OP_OR, OP_AND_NOT, OP_XOR, OP_AND_MAYBE, OP_FILTER,OP_NEAR,OP_PHRASE or OP_ELITE_SET. See Search::Xapian for descriptions of these constants.

get_default_op

Returns the default operator for joining elements.

set_database <database>

Pass a Search::Xapian::Database object to be used for searching.

parse_query <query_string> [<flags>]

parses the query string according to the rules defined in the query parser documentation below. Allows you to specify certain flags to modify the searching behavior:

  FLAG_BOOLEAN=1, FLAG_PHRASE=2, FLAG_LOVEHATE=4, 
  FLAG_BOOLEAN_ANY_CASE=8, FLAG_WILDCARD = 16 

default flags are FLAG_PHRASE,FLAG_BOOLEAN and FLAG_LOVEHATE

add_prefix <field> <prefix>

Add a probabilistic term prefix. E.g. $qp->add_prefix("author", "A");

Allows the user to search for author:orwell which will search for the term "Aorwel" (assuming English stemming is in use). Multiple fields can be mapped to the same prefix (so you can e.g. make title: and subject: aliases for each other).

Parameters: field The user visible field name prefix The term prefix to map this to

add_boolean_prefix <field> prefix

Add a boolean term prefix allowing the user to restrict a search with a boolean filter specified in the free text query. E.g. $p->add_boolean_prefix("site", "H");

Allows the user to restrict a search with site:xapian.org which will be converted to Hxapian.org combined with any probabilistic query with OP_FILTER.

Multiple fields can be mapped to the same prefix (so you can e.g. make site: and domain: aliases for each other).

Parameters: field The user visible field name prefix The term prefix to map this t

REFERENCE

  http://www.xapian.org/docs/queryparser.html
  http://www.xapian.org/docs/sourcedoc/html/classXapian_1_1QueryParser.html

TODO

Implement Xapian::Stopper.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 137:

Expected text after =item, not a bullet