=encoding UTF-8 =head1 NAME WebService::Solr::Tiny - Perl interface to Apache Solr =for html =head1 SYNOPSIS use WebService::Solr::Tiny 'solr_escape'; my $solr = WebService::Solr::Tiny->new; # Simple $solr->search('foo'); # Complex $solr->search( '{!lucene q.op=AND df=text}myfield:foo +bar -baz', debugQuery => 'true', fl => 'id,name,price', fq => [ 'foo:"' . solr_escape($foo) . '"', 'popularity:[10 TO *]', 'section:0', ], omitHeader => 'true', rows => 20, sort => 'inStock desc, price asc', start => 10, ); =head1 DESCRIPTION WebService::Solr::Tiny is similar to, and inspired by L, but with an aim to be tinier. =head1 FUNCTIONS The functions in this section are exportable on request. =head2 solr_escape C is a small utility subroutine for escaping characters that have meaning in Lucene query syntax. =head2 solr_query C aims to make it easier for users of L to migrate to this distribution. It takes the same arguments as the constructor of a L object, and returns a string that is equivalent to stringifying that object. =head1 METHODS =head2 new Construct a new WebService::Solr::Tiny instance. The constructor takes the following parameters: =over =item C The HTTP user-agent to use to make the requests. Defaults to an L instance. =item C A code reference to use for decoding responses. Defaults to using C from L. =item C A hash reference with default parameters that will be passed along as part of every request. The values in this hash will be merged with those passed to C. Defaults to an empty hash reference. =item C The URL of the collection requests will be sent to. Defaults to C. =back =head2 search Sends a request to Solr. Takes a string to be used as a Solr query, and an optional list of key-value pairs to be used as additional query parameters to qualify the request. The query defaults to the empty string, and will be passed as the C query parameter. No special protections are in place to prevent any of the additional arguments from overwriting this. If any value has been set as part of the C in the constructor, these will be merged with the arguments to this function. The final set of parameters will be converted to a query parameter string using L. See that module's documentation for more details about how these values will be processed. In the event of a failure of any kind, this function will croak with the content of the response. On success, the full content of the response will be passed to the code ref specified in the C parameter to the constructor, and the result of this will be this method's return value. =head1 PERFORMANCE One way to increase the performance of this module is to swap out the decoder. By default Solr returns JSON, therefore the fastest decoder for this would be L. You can swap out L for L like so: use JSON::XS (); use WebService::Solr::Tiny; my $solr = WebService::Solr::Tiny->new( decoder => \&JSON::XS::decode_json ); However it's possible to make Solr return a compact binary format known as JavaBin, to do so we send C with each request. Couple that with the CPAN module L like so: use JavaBin (); use WebService::Solr::Tiny; my $solr = WebService::Solr::Tiny->new( decoder => \&JavaBin::from_javabin, default_args => { wt => 'javabin' }, ); Both of these should be faster than the stock configuration, but require a C compiler and are generally not as portable, YMMV so benchmark first. =head1 SEE ALSO L =head1 COPYRIGHT AND LICENSE Copyright © 2015 by James Raspass This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.