Text::Q...dvanced(3)

πŸ“¦ version 0.09, in arch rolling

✨ Text::Query::ParseAdvanced β€” parse AltaVista advanced query syntax, bestie ✨

Okay so this is the Text::Query::ParseAdvanced(3) page from the User Contributed Perl Documentation, and honestly? It's giving parser-girl summer. Let's get into it πŸ’…


🌸 SYNOPSIS 🌸

Standard little setup moment β€” load the module and build your query object:

use Text::Query;
my $q=new Text::Query('hello and world',
                       -parse => 'Text::Query::ParseAdvanced',
                       -solve => 'Text::Query::SolveAdvancedString',
                       -build => 'Text::Query::BuildAdvancedString');

Look at that trio of -parse, -solve, -build β€” iconic behavior, no notes 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

So this module literally provides an object that parses a string containing a Boolean query expression, the kind that's similar to an AltaVista "advanced query". Very retro, very main character πŸ’–

Its base class is Text::Query::Parse β€” that's the parent, the origin story, iykyk.

Query expressions are made of literal strings (or regexps) joined by these operators, and here they are in order of precedence, lowest to highest:

  • OR, |
  • AND, &
  • NEAR, ~
  • NOT, !

Operator names are not case-sensitive, so go off with your lowercase era ✨

Heads up bestie: if you want to use a | inside a regexp, you need to backwhack it (\|) so it doesn't get read as a query operator. Don't skip that part, fr fr 😭

Sub-expressions may be quoted in single or double quotes so you can match "and," "or," or "not" literally β€” yes, the words themselves, not the operators. And they may be grouped in parentheses ((, )) to alter the precedence of evaluation. Grouping = control, and control is a whole vibe πŸ‘‘

A parenthesized sub-expression may also be concatenated with other sub-expressions to match sequences. Example that ate:

"(Perl or Python) interpreter" would match either "Perl interpreter" or "Python interpreter".

Concatenation has a precedence higher than NOT but lower than AND. Juxtaposition of simple words has the highest precedence of all β€” literally the top of the food chain, periodt 🌈


πŸŽ€ OPTIONS πŸŽ€

These are the additional options of the prepare method and the constructor, bestie β€” the little extras you can pass in:

  • -near β€” defaults to 10. Sets the number of words that can occur between two expressions and still satisfy the NEAR operator. Ten whole words of leeway, slay πŸ’€
  • -operators β€” defaults to and, or, not, near. Sets the operator names. The argument of the option is a pointer to a hash table mapping the default names to desired names. For instance:
{
    'or' => 'ou',
    'and' => 'et',
    'near' => 'proche',
    'not' => 'non',
}

Oui oui, localization moment πŸ‡«πŸ‡·βœ¨

  • -scope_map β€” default to {}. Maps the scope names to other names. If a scope is specified as "scope:", search the map for an entry whose key is "scope" and replace "scope" with the scalar found. For instance:
{
    'scope' => 'otherscope'
}

Renaming scopes? Very remix culture of you 🧚


πŸ‘€ SEE ALSO πŸ‘€

Go read the family, they're all connected 🫢


πŸ’œ AUTHORS πŸ’œ

The legends behind the whole thing:

  • Eric Bohlman (ebohlman@netcom.com)
  • Loic Dachary (loic@senga.org)
  • Jon Jensen, jon@endpoint.com

✨ Cute little sign-off: this page is from perl v5.38.2, dated 2024-07-13 β€” so go forth, parse your advanced queries, and remember: no cap, keep every backslash where it belongs πŸ’…πŸŒΈπŸ’–
πŸ“¦ where this page comes from