WebService::Solr(3pm) | User Contributed Perl Documentation | WebService::Solr(3pm) |
WebService::Solr - Module to interface with the Solr (Lucene) webservice
my $solr = WebService::Solr->new; $solr->add( @docs ); my $response = $solr->search( $query ); for my $doc ( $response->docs ) { print $doc->value_for( $id ); }
WebService::Solr is a client library for Apache Lucene's Solr; an enterprise-grade indexing and searching platform.
Enabling HTTP Keep-Alive is as simple as passing your custom user-agent to the constructor.
my $solr = WebService::Solr->new( $url, { agent => LWP::UserAgent->new( keep_alive => 1 ) } );
Visit LWP::UserAgent's documentation for more information and available options.
Creates a new WebService::Solr instance. If $url is omitted, then "http://localhost:8983/solr" is used as a default. Available options are listed in the ACCESSORS section.
A Moo override to allow our custom constructor.
Adds a number of documents to the index. Returns true on success, false otherwise. A document can be a WebService::Solr::Document object or a structure that can be passed to "WebService::Solr::Document->new". Available options as of Solr 1.4 are:
Alias for "add()".
Deletes documents matching the options provided. The delete operation currently accepts "query" and "id" parameters. Multiple values can be specified as array references.
# delete documents matching "title:bar" or uniqueId 13 or 42 $solr->delete( { query => 'title:bar', id => [ 13, 42 ], } );
Deletes all documents matching the id specified. Returns true on success, false otherwise.
Deletes documents matching $query. Returns true on success, false otherwise.
Searches the index given a $query. Returns a WebService::Solr::Response object. All key-value pairs supplied in "\%options" are serialized in the request URL.
If filter queries are needed, create WebService::Solr::Query objects and pass them into the %options. For example, if you were searching a database of books for a subject of "Perl", but wanted only paperbacks and a copyright year of 2011 or 2012:
my $query = WebService::Solr::Query->new( { subject => 'Perl' } ); my %options = ( fq => [ WebService::Solr::Query->new( { binding => 'Paperback' } ), WebService::Solr::Query->new( { year => [ 2011, 2012 ] } ), ], ); my $response = $solr->search( $query, \%options );
The filter queries are typically added when drilling down into search results and selecting a facet to drill into.
In order to enable facets, the option "facet => "on"" must be passed. Facet options are detailed in the wiki (https://wiki.apache.org/solr/SimpleFacetParameters).
Get suggestions from a list of terms for a given field. The Solr wiki has more details about the available options (http://wiki.apache.org/solr/TermsComponent)
Sends a commit command. Returns true on success, false otherwise. You must do a commit after an add, update or delete. By default, autocommit is enabled. You may disable autocommit to allow you to issue commit commands manually:
my $solr = WebService::Solr->new( undef, { autocommit => 0 } ); $solr->add( $doc ); # will not automatically call commit() $solr->commit;
Options as of Solr 1.4 include:
This method will rollback any additions/deletions since the last commit.
Sends an optimize command. Returns true on success, false otherwise.
Options as of Solr 1.4 are the same as "commit()".
Sends a basic ping request. Returns true on success, false otherwise.
Performs a simple "GET" request appending $path to the base URL and using key-value pairs from "\%query" to generate the query string. This should allow you to access parts of the Solr API that don't yet have their own correspondingly named function (e.g. "dataimport" ).
Andy Lester "andy@petdance.com"
Brian Cassidy <bricas@cpan.org>
Kirk Beers
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.
2020-01-19 | perl v5.30.0 |