WebSer...::Query(3pm)
π WebSer...::Query(3pm) π
okay bestie, so this is WebService::Solr::Query from the User Contributed Perl Documentation, and it's about to make your Solr life so much easier, no cap β¨
πΈ NAME πΈ
WebService::Solr::Query β the abstract query syntax for Solr queries π¦
π SYNOPSIS π
my $query = WebService::Solr::Query->new( { foo => 'bar' } );
my $result = $solr->search( $query );
like. that's it. that's the whole vibe π
β¨ DESCRIPTION β¨
so WebService::Solr::Query gives you a programmatic way to build queries that get sent off to Solr, which is lowkey the best way to do it because hand-writing query strings is giving chaos π
syntax-wise, it tries so hard to stay as close to SQL::Abstract WHERE clauses as it possibly can, with the obvious exceptions for idioms that just... don't exist in SQL π
and here's the part you need to know: just like values in SQL::Abstract get SQL-escaped, this module does the appropriate Solr-escaping on all values you pass to the object. see escape(). it's doing the work so you don't have to π«Ά
π QUERY SYNTAX π
π Key-Value Pairs
the simplest way to search. iconic. the classic.
my $q = WebService::Solr::Query->new( { foo => 'bar' } );
# RESULT: (foo:"bar")
π Implicit AND and OR
by default, data you hand over as a HASHREF gets AND'ed together. it's automatic, bestie.
my $q = WebService::Solr::Query->new( { foo => 'bar', baz => 'quux' } );
# RESULT: (foo:"bar" AND baz:"quux")
and furthermore (yes we're going there), data you hand over as an ARRAYREF gets OR'ed together:
my $q = WebService::Solr::Query->new( { foo => [ 'bar', 'baz' ] } );
# RESULT: (foo:"bar" OR foo:"baz")
π¦ Nested AND and OR
being able to nest AND and OR boolean operators is essential to express complex queries. essential! non-negotiable! and that's literally why the -and and -or prefixes exist π
my $q = WebService::Solr::Query->new( { foo => [
-and => { -prohibit => 'bar' }, { -require => 'baz' }
] } );
# RESULT: (((-foo:"bar") AND (+foo:"baz")))
my $q = WebService::Solr::Query->new( { foo => [
-or => { -require => 'bar' }, { -prohibit => 'baz' }
] } );
# RESULT: (((+foo:"bar") OR (-foo:"baz")))
π Default Field
wanna search the default field? use the -default prefix, easy peasy π
my $q = WebService::Solr::Query->new( { -default => 'bar' } );
# RESULT: ("bar")
π Require/Prohibit
my $q = WebService::Solr::Query->new( { foo => { -require => 'bar' } } );
# RESULT: (+foo:"bar")
my $q = WebService::Solr::Query->new( { foo => { -prohibit => 'bar' } } );
# RESULT: (-foo:"bar")
π₯ Range
there are two types of range queries bestie: inclusive (-range_inc) and exclusive (-range_exc). and plot twist, the -range prefix can be used in place of -range_inc because we're flexible like that π
my $q = WebService::Solr::Query->new( { foo => { -range => ['a', 'z'] } } );
# RESULT: (+foo:[a TO z])
my $q = WebService::Solr::Query->new( { foo => { -range_exc => ['a', 'z'] } } );
# RESULT: (+foo:{a TO z})
β Boost
my $q = WebService::Solr::Query->new( { foo => { -boost => [ 'bar', '2.0' ] } } );
# RESULT: (foo:"bar"^2.0)
π§ Proximity
my $q = WebService::Solr::Query->new( { foo => { -proximity => [ 'bar baz', 10 ] } } );
# RESULT: (foo:"bar baz"~10)
π«Ά Fuzzy
my $q = WebService::Solr::Query->new( { foo => { -fuzzy => [ 'bar', '0.8' ] } } );
# RESULT: (foo:bar~0.8)
π Literal Queries
okay so if you specify a scalar ref as a value in a key-value pair, that lets arbitrary queries get sent across the line. π¨
NB: this will bypass any data massaging done on regular strings β so the onus of properly escaping the data is left to you. yes, you. the main character. no pressure π
my $q = WebService::Solr::Query->new( { '*' => \'*' } )
# RESULT (*:*)
π ACCESSORS π
queryβ stores the original query structure β¨
πΈ METHODS πΈ
π¦ new( \%query )
creates a new query object with the given hashref. brand new baby query π
π stringify( )
converts the supplied structure into a Solr/Lucene query. it's giving translation services.
π₯ escape( $value )
the following values must be escaped in a search value:
+ - & | ! ( ) { } [ ] ^ " ~ * ? : \
NB: values sent to new() are automatically escaped for you. we got you π«Ά
π
unescape( $value )
unescapes values escaped in escape(). the reverse moment.
β D
debugging constant, default: off.
π BUILDARGS
Moo method to handle input to new().
π SEE ALSO π
WebService::Solrhttp://wiki.apache.org/solr/SolrQuerySyntax
π AUTHORS π
- Andy Lester
andy@petdance.com - Brian Cassidy
<bricas@cpan.org> - Jos Boumans
<kane@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright 2008-2014 National Adult Literacy Database Copyright 2015-2020 Andy Lester
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie, go forth and build queries that eat π β¨
signing off from the world of perl v5.36.0, dated 2022-10-16, WebSer...::Query(3pm) β ily, go slay π¦π
π¦ where this page comes from
- ubuntu noble: libwebservice-solr-perl 0.44-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libwebservice-solr-perl 0.44-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libwebservice-solr-perl 0.44-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms