Catmandu-Solr-0.0304000755001750001750 013541102541 15052 5ustar00nsteenlansteenla000000000000README100644001750001750 233013541102541 16011 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304NAME Catmandu::Solr - Catmandu modules for working with solr endpoints SYNOPSIS # From the command line # Import data into Solr $ catmandu import JSON to Solr < data.json # Export data from ElasticSearch $ catmandu export Solr to JSON > data.json # Export only one record $ catmandu export Solr --id 1234 # Export using an Solr query $ catmandu export Solr --query "name:Recruitment OR name:college" # Export using a CQL query (needs a CQL mapping) $ catmandu export Solr --q "name any college" AUTHOR Nicolas Steenlant, nicolas.steenlant at ugent.be Patrick Hochstenbach, patrick.hochstenbach at ugent.be Nicolas Franck, nicolas.franck at ugent.be SYNOPSIS For documentation on these fixes see: Catmandu::Store::Solr Catmandu::Importer::Solr SEE ALSO Catmandu::Store Catmandu LICENSE AND COPYRIGHT This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. t000755001750001750 013541102541 15236 5ustar00nsteenlansteenla000000000000Catmandu-Solr-0.030400.t100644001750001750 42613541102541 15764 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/t#!/usr/bin/env perl use strict; use warnings; use Test::More; my @pkgs = qw( Catmandu::Store::Solr Catmandu::Store::Solr::Bag Catmandu::Store::Solr::Searcher Catmandu::Store::Solr::CQL Catmandu::Importer::Solr ); require_ok $_ for @pkgs; done_testing 5; Changes100644001750001750 464013541102541 16432 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304Revision history for Catmandu-Solr 0.0304 2019-09-20 09:52:59 CEST - add missing dependency 0.0303 2017-10-03 16:55:18 CEST - support http keep-alive 0.0302 2017-04-20 15:36:51 CEST - fix typo - more pod 0.0301 2017-04-06 18:15:24 CEST - use Catmandu::Bag provided id/key/id_field 0.03 2017-03-23 14:31:04 CET - use new Catmandu::CQLSearchable role 0.02154 2016-12-15 15:28:58 CET - fix bug that prevents records from last page to be returned 0.02153 2016-12-12 12:24:20 CET - fix typo in Catmandu::Store::Solr::SQL that made cql mapping field 'field' impossible 0.02152 2016-05-31 13:32:22 CEST - method search contains key 'highlighting' now 0.02151 2016-04-21 14:59:26 CEST - fix perlpod errors in Catmandu::Store::Solr 0.0215 2016-02-26 15:07:19 CET - add option 'fl' to Catmandu::Store::Solr::Searcher to optimize access - fix bug in Catmandu::Store::Solr::Bag ( 'throw' ) - make more store transaction safe - fix bug Catmandu::Importer::Solr->count 0.0214 2016-02-25 14:47:24 CET - normalize_query now delivers explicit lucene query to match all documents 0.0213 2016-02-23 - Catmandu::Store::Solr has role Catmandu::Transactional - dependency on Catmandu 1.0 0.0212 2016-02-12 - set query type in filters explicit to lucene 0.0211 2016-02-11 - make cql parser object oriƫnted - add documentation for cql_mapping 0.0210 2015-11-30 - add option "on_error" to Catmandu::Store::Solr 0.0209 2015-02-25 - removed the need to flush buffers within transactions. When the transaction is done, all buffers of all bags are now flushed automatically. 0.0208 2014-01-26 - added support for transactions 0.0207 2014-12-05 - bug fix: delete by query only supports lucene queries. LocalParams are forbidden 0.0206 2014-11-18 - merged pull request from Jakob Voss to make the field '_id' and '_bag' configurable 0.0205 2014-11-17 - changed distribution name to Catmandu-Solr - added Catmandu::Importer::Solr 0.0204 2014-03-25 - fq can be an array ref - optimized versions of count and total - include spellcheck in hits 0.0203 2013-09-04 - update dependencies 0.0202 2013-09-02 - disable facets, spellcheck if not needed 0.0201 2013-03-26 - import confess 0.02 2012-12-03 - initial release LICENSE100644001750001750 4367413541102541 16176 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304This software is copyright (c) 2019 by Nicolas Steenlant. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2019 by Nicolas Steenlant. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2019 by Nicolas Steenlant. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End cpanfile100644001750001750 71013541102541 16615 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304#requirements on 'test' => sub { requires 'Catmandu::Store::Hash','0'; requires 'Software::License','0'; requires 'Test::Exception','0'; requires 'Test::More','0'; }; requires 'CQL::Parser','1.12'; requires 'Catmandu','>=1.0503'; requires 'LWP::UserAgent', '0'; requires 'Module::Build', '>=0.4229'; # travis ci requires 'Moo','>=1.00'; requires 'MooX::Aliases', '>=0.001006'; requires 'WebService::Solr','0.16'; requires 'perl','5.10.1'; dist.ini100644001750001750 6613541102541 16541 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304name = Catmandu-Solr [@Milla] installer = ModuleBuild Build.PL100644001750001750 262313541102541 16432 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304 # This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.012. use strict; use warnings; use Module::Build 0.28; my %module_build_args = ( "build_requires" => { "Module::Build" => "0.4229" }, "configure_requires" => { "Module::Build" => "0.28" }, "dist_abstract" => "Catmandu modules for working with solr endpoints", "dist_author" => [ "Nicolas Steenlant, C<< nicolas.steenlant at ugent.be >>" ], "dist_name" => "Catmandu-Solr", "dist_version" => "0.0304", "license" => "perl", "module_name" => "Catmandu::Solr", "recursive_test_files" => 1, "requires" => { "CQL::Parser" => "1.12", "Catmandu" => "1.0503", "LWP::UserAgent" => 0, "Module::Build" => "0.4229", "Moo" => "1.00", "MooX::Aliases" => "0.001006", "WebService::Solr" => "0.16", "perl" => "v5.10.1" }, "test_requires" => { "Catmandu::Store::Hash" => 0, "Software::License" => 0, "Test::Exception" => 0, "Test::More" => 0 } ); my %fallback_build_requires = ( "Catmandu::Store::Hash" => 0, "Module::Build" => "0.4229", "Software::License" => 0, "Test::Exception" => 0, "Test::More" => 0 ); unless ( eval { Module::Build->VERSION(0.4004) } ) { delete $module_build_args{test_requires}; $module_build_args{build_requires} = \%fallback_build_requires; } my $build = Module::Build->new(%module_build_args); $build->create_build_script; META.yml100644001750001750 307413541102541 16410 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304--- abstract: 'Catmandu modules for working with solr endpoints' author: - 'Nicolas Steenlant, C<< nicolas.steenlant at ugent.be >>' build_requires: Catmandu::Store::Hash: '0' Module::Build: '0.4229' Software::License: '0' Test::Exception: '0' Test::More: '0' configure_requires: Module::Build: '0.28' dynamic_config: 0 generated_by: 'Dist::Milla version v1.0.20, Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Catmandu-Solr no_index: directory: - eg - examples - inc - share - t - xt requires: CQL::Parser: '1.12' Catmandu: '1.0503' LWP::UserAgent: '0' Module::Build: '0.4229' Moo: '1.00' MooX::Aliases: '0.001006' WebService::Solr: '0.16' perl: v5.10.1 resources: bugtracker: https://github.com/LibreCat/Catmandu-Solr/issues homepage: https://github.com/LibreCat/Catmandu-Solr repository: https://github.com/LibreCat/Catmandu-Solr.git version: '0.0304' x_contributors: - 'Jakob Voss ' - 'Mohammad S Anwar ' - 'Nicolas Franck ' - 'Nicolas Franck ' - 'Nicolas Steenlant ' - 'Nicolas Steenlant ' - 'njfranck ' - 'Patrick Hochstenbach ' - 'Pieter De Praetere ' x_generated_by_perl: v5.28.1 x_serialization_backend: 'YAML::Tiny version 1.73' x_static_install: 0 MANIFEST100644001750001750 60713541102541 16247 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. Build.PL Changes LICENSE MANIFEST META.json META.yml README cpanfile dist.ini lib/Catmandu/Importer/Solr.pm lib/Catmandu/Solr.pm lib/Catmandu/Store/Solr.pm lib/Catmandu/Store/Solr/Bag.pm lib/Catmandu/Store/Solr/CQL.pm lib/Catmandu/Store/Solr/Searcher.pm t/00.t t/01-bag.t t/02-importer.t t/author-pod-syntax.t META.json100644001750001750 505213541102541 16556 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304{ "abstract" : "Catmandu modules for working with solr endpoints", "author" : [ "Nicolas Steenlant, C<< nicolas.steenlant at ugent.be >>" ], "dynamic_config" : 0, "generated_by" : "Dist::Milla version v1.0.20, Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Catmandu-Solr", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.4229" } }, "configure" : { "requires" : { "Module::Build" : "0.28" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.20", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "CQL::Parser" : "1.12", "Catmandu" : "1.0503", "LWP::UserAgent" : "0", "Module::Build" : "0.4229", "Moo" : "1.00", "MooX::Aliases" : "0.001006", "WebService::Solr" : "0.16", "perl" : "v5.10.1" } }, "test" : { "requires" : { "Catmandu::Store::Hash" : "0", "Software::License" : "0", "Test::Exception" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/LibreCat/Catmandu-Solr/issues" }, "homepage" : "https://github.com/LibreCat/Catmandu-Solr", "repository" : { "type" : "git", "url" : "https://github.com/LibreCat/Catmandu-Solr.git", "web" : "https://github.com/LibreCat/Catmandu-Solr" } }, "version" : "0.0304", "x_contributors" : [ "Jakob Voss ", "Mohammad S Anwar ", "Nicolas Franck ", "Nicolas Franck ", "Nicolas Steenlant ", "Nicolas Steenlant ", "njfranck ", "Patrick Hochstenbach ", "Pieter De Praetere " ], "x_generated_by_perl" : "v5.28.1", "x_serialization_backend" : "Cpanel::JSON::XS version 4.12", "x_static_install" : 0 } 01-bag.t100644001750001750 663513541102541 16544 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/t#!/usr/bin/env perl use strict; use warnings; use Test::More; use Test::Exception; require Catmandu::Store::Hash; require Catmandu::Store::Solr; my $solr_url = $ENV{T_SOLR_URL}; my $solr_bag = $ENV{T_SOLR_BAG} || "data"; my $solr_id_field = $ENV{T_SOLR_ID_FIELD} || "_id"; my $solr_bag_field = $ENV{T_SOLR_BAG_FIELD} || "_bag"; unless (defined($solr_url) && $solr_url ne "") { plan skip_all => "no environment variable T_SOLR_URL found"; } else { my $store; my $bag; lives_ok( sub { $store = Catmandu::Store::Solr->new( url => $solr_url, id_field => $solr_id_field, bag_field => $solr_bag_field ); }, "store created" ); lives_ok( sub { $bag = $store->bag($solr_bag); }, "bag created" ); my $record = {_id => "test"}; #delete all lives_ok(sub {$bag->delete_all; $bag->commit();}, "bag delete all"); #bag add lives_ok(sub {$bag->add($record); $bag->commit();}, "bag add"); #bag get my $new_record; lives_ok(sub {$new_record = $bag->get($record->{_id});}, "bag get"); is_deeply($record, $new_record, "retrieved record equal"); #bag delete lives_ok(sub {$bag->delete($record->{_id}); $bag->commit();}, "bag delete"); is($bag->get($record->{_id}), undef, "record deleted"); #bag add_many my @records; for (1 .. 10) { push @records, {_id => "test-$_"}; } lives_ok(sub {$bag->add_many(\@records); $bag->commit();}, "bag add_many"); my $num = 0; lives_ok(sub {$num = $bag->count();}, "bag count"); is($num, scalar(@records), "bag count"); #bag delete_all lives_ok(sub {$bag->delete_all(); $bag->commit();}, "bag delete"); is($bag->count(), 0, "all records deleted"); #transactions dies_ok( sub { $bag->store->transaction( sub { $bag->add({_id => "a"}); $bag->add({_id => "b"}); die("failed"); } ); }, "bag transaction must die" ); is($bag->count(), 0, "bag transaction had no effect"); #reify my $reify; lives_ok(sub {$reify = Catmandu::Store::Hash->new()->bag();}, "reify created"); #add many lives_ok( sub { for (1 .. 10) { $reify->add({_id => "test-$_", title => "test-$_"}); $reify->commit(); } }, "added many records to reify" ); #copy to solr without title lives_ok( sub { $bag->add_many( $reify->map( sub { +{_id => $_[0]->{_id}}; } ) ); $bag->commit(); }, "copied reify to solr bag" ); #reify records my $reified_records; lives_ok( sub { $reified_records = $bag->searcher(fl => $solr_id_field)->map( sub { $reify->get($_[0]->{_id}); } )->to_array(); }, "retrieved reified records" ); #compare my $from = [sort {$a->{_id} cmp $b->{_id}} @$reified_records]; my $to = [sort {$a->{_id} cmp $b->{_id}} @{$reify->to_array()}]; is_deeply($from, $to, "all records equal"); done_testing 20; } 02-importer.t100644001750001750 162213541102541 17644 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/t#!/usr/bin/env perl use strict; use warnings; use Test::More; use Test::Exception; require Catmandu::Importer::Solr; my $solr_url = $ENV{T_SOLR_URL}; my $solr_bag = $ENV{T_SOLR_BAG} || "data"; my $solr_id_field = $ENV{T_SOLR_ID_FIELD} || "_id"; my $solr_bag_field = $ENV{T_SOLR_BAG_FIELD} || "_bag"; unless (defined($solr_url) && $solr_url ne "") { plan skip_all => "no environment variable T_SOLR_URL found"; } else { my $importer; lives_ok( sub { $importer = Catmandu::Importer::Solr->new( url => $solr_url, id_field => $solr_id_field, bag_field => $solr_bag_field, bag => $solr_bag ); }, "importer created" ); lives_ok( sub { my $c = $importer->count(); }, "importer count" ); done_testing 2; } Catmandu000755001750001750 013541102541 17275 5ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/libSolr.pm100644001750001750 245313541102541 20716 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandupackage Catmandu::Solr; # ABSTRACT: Catmandu modules for working with solr endpoints our $VERSION = "0.0304"; =head1 NAME Catmandu::Solr - Catmandu modules for working with solr endpoints =head1 SYNOPSIS # From the command line # Import data into Solr $ catmandu import JSON to Solr < data.json # Export data from ElasticSearch $ catmandu export Solr to JSON > data.json # Export only one record $ catmandu export Solr --id 1234 # Export using an Solr query $ catmandu export Solr --query "name:Recruitment OR name:college" # Export using a CQL query (needs a CQL mapping) $ catmandu export Solr --q "name any college" =head1 AUTHOR Nicolas Steenlant, C<< nicolas.steenlant at ugent.be >> Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >> Nicolas Franck, C<< nicolas.franck at ugent.be >> =head1 SYNOPSIS For documentation on these fixes see: L L =head1 SEE ALSO L L =head1 LICENSE AND COPYRIGHT This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See L for more information. =cut 1; author-pod-syntax.t100644001750001750 45413541102541 21154 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Store000755001750001750 013541102541 20371 5ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/CatmanduSolr.pm100644001750001750 2035513541102541 22033 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/Storepackage Catmandu::Store::Solr; use Catmandu::Sane; use Catmandu::Util qw(:is :array); use Moo; use MooX::Aliases; use WebService::Solr; use Catmandu::Store::Solr::Bag; use Catmandu::Error; use LWP::UserAgent; with 'Catmandu::Store'; with 'Catmandu::Transactional'; =head1 NAME Catmandu::Store::Solr - A searchable store backed by Solr =cut our $VERSION = '0.0304'; =head1 SYNOPSIS # From the command line # Import data into Solr $ catmandu import JSON to Solr < data.json # Export data from ElasticSearch $ catmandu export Solr to JSON > data.json # Export only one record $ catmandu export Solr --id 1234 # Export using an Solr query $ catmandu export Solr --query "name:Recruitment OR name:college" # Export using a CQL query (needs a CQL mapping) $ catmandu export Solr --q "name any college" # From Perl use Catmandu::Store::Solr; my $store = Catmandu::Store::Solr->new(url => 'http://localhost:8983/solr' ); my $obj1 = $store->bag->add({ name => 'Patrick' }); printf "obj1 stored as %s\n" , $obj1->{_id}; # Force an id in the store my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' }); # send all changes to solr (committed automatically) $store->bag->commit; #transaction: rollback issued after 'die' $store->transaction(sub{ $bag->delete_all(); die("oops, didn't want to do that!"); }); my $obj3 = $store->bag->get('test123'); $store->bag->delete('test123'); $store->bag->delete_all; # All bags are iterators $store->bag->each(sub { ... }); $store->bag->take(10)->each(sub { ... }); # Search # Any extra arguments will be passed on as is to Solr my $hits = $store->bag->search(query => 'name:Patrick'); =cut has url => (is => 'ro', default => sub {'http://localhost:8983/solr'}); has keep_alive => (is => 'ro', default => sub {0}); has solr => (is => 'lazy'); has bag_key => (is => 'lazy', alias => 'bag_field'); has on_error => ( is => 'ro', isa => sub { array_includes([qw(throw ignore)], $_[0]) or die("on_error must be 'throw' or 'ignore'"); }, lazy => 1, default => sub {"throw"} ); has _bags_used => (is => 'ro', lazy => 1, default => sub {[];}); around 'bag' => sub { my $orig = shift; my $self = shift; my $bags_used = $self->_bags_used; unless (array_includes($bags_used, $_[0])) { push @$bags_used, $_[0]; } $orig->($self, @_); }; sub _build_solr { my ($self) = @_; WebService::Solr->new( $_[0]->url, { autocommit => 0, default_params => {wt => 'json'}, agent => LWP::UserAgent->new(keep_alive => $self->keep_alive), } ); } sub _build_bag_key { $_[0]->key_for('bag'); } sub transaction { my ($self, $sub) = @_; if ($self->{_tx}) { return $sub->(); } my $solr = $self->solr; my @res; eval { #flush buffers of all known bags ( with commit=true ), to ensure correct state for my $bag_name (@{$self->_bags_used}) { $self->bag($bag_name)->commit; } #mark store as 'in transaction'. All subsequent calls to commit only flushes buffers without setting 'commit' to 'true' in solr $self->{_tx} = 1; #transaction @res = $sub->(); #flushing buffers of all known bags (with commit=false) for my $bag_name (@{$self->_bags_used}) { $self->bag($bag_name)->commit; } #commit in solr $solr->commit; #remove mark 'in transaction' $self->{_tx} = 0; 1; } or do { my $err = $@; #remove remaining documents from all buffers, because they were added during the transaction for my $bag_name (@{$self->_bags_used}) { $self->bag($bag_name)->clear_buffer; } #rollback in solr eval {$solr->rollback}; #remove mark 'in transaction' $self->{_tx} = 0; Catmandu::Error->throw($err); }; @res; } =head1 SOLR SCHEMA The Solr schema needs to support at least the identifier field (C<_id> by default) and a bag field (C<_bag> by default) to be able to store Catmandu items: # In schema.xml The names of these fields can optionally be changed using the C and C<_bag> configuration parameters of L. The C<_id> will contain the record identifier. The C<_bag> field will contain a string to support L-s in Solr. =head1 CONFIGURATION =over =item url URL of Solr core Default: C =item id_field Name of unique field in Solr core. Default: C<_id> This Solr field is mapped to C<_id> when retrieved =item bag_field Name of field in Solr we can use to split the core into 'bags'. Default: C<_bag> This Solr field is mapped to C<_bag> when retrieved =item on_error Action to take when records cannot be saved to Solr. Default: throw. Available: ignore. =back =head1 METHODS =head2 new( url => $url ) =head2 new( url => $url, id_field => '_id', bag_field => '_bag' ) =head2 new( url => $url, bags => { data => { cql_mapping => \%mapping } } ) Creates a new Catmandu::Store::Solr store connected to a Solr core, specificied by $url. The store supports CQL searches when a cql_mapping is provided. This hash contains a translation of CQL fields into Solr searchable fields. # Example mapping $cql_mapping = { title => { op => { 'any' => 1 , 'all' => 1 , '=' => 1 , '<>' => 1 , 'exact' => {field => 'mytitle.exact' } } , sort => 1, field => 'mytitle', cb => ['Biblio::Search', 'normalize_title'] } } The CQL mapping above will support for the 'title' field the CQL operators: any, all, =, <> and exact. For all the operators the 'title' field will be mapping into the Solr field 'mytitle', except for the 'exact' operator. In case of 'exact' we will search the field 'mytitle.exact'. The CQL has an optional callback field 'cb' which contains a reference to subroutines to rewrite or augment the search query. In this case, in the Biblio::Search package there is a normalize_title subroutine which returns a string or an ARRAY of string with augmented title(s). E.g. package Biblio::Search; sub normalize_title { my ($self,$title) = @_; my $new_title =~ s{[^A-Z0-9]+}{}g; $new_title; } 1; =head2 transaction When you issue $bag->commit, all changes made in the buffer are sent to solr, along with a commit. So committing in Catmandu merely means flushing changes;-). When you wrap your subroutine within 'transaction', this behaviour is disabled temporarily. When you call 'die' within the subroutine, a rollback is sent to solr. Remember that transactions happen at store level: after the transaction, all buffers of all bags are flushed to solr, and a commit is issued in solr. # Record 'test' added $bag->add({ _id => "test" }); # Buffer flushed, and 'commit' sent to solr $bag->commit(); $bag->store->transaction(sub{ $bag->add({ _id => "test",title => "test" }); # Call to die: rollback sent to solr die("oops, didn't want to do that!"); }); # Record is still { _id => "test" } =head1 INHERITED METHODS This Catmandu::Store implements: =over 3 =item L =item L =back Each Catmandu::Bag in this Catmandu::Store implements: =over 3 =item L =item L =item L =back =head1 SEE ALSO L, L =head1 AUTHOR Nicolas Steenlant, C<< nicolas.steenlant at ugent.be >> Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >> Nicolas Franck, C<< nicolas.franck at ugent.be >> Pieter De Praetere =head1 LICENSE AND COPYRIGHT This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 1; Importer000755001750001750 013541102541 21076 5ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/CatmanduSolr.pm100644001750001750 462013541102541 22515 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/Importerpackage Catmandu::Importer::Solr; use Catmandu::Sane; use Catmandu::Store::Solr; use Catmandu; use Moo; our $VERSION = '0.0304'; with 'Catmandu::Importer'; has fq => (is => 'ro'); has query => (is => 'ro'); has url => (is => 'ro'); has bag => (is => 'ro'); has id_field => (is => 'ro', default => sub {'_id'}); has bag_field => (is => 'ro', default => sub {'_bag'}); has _bag => (is => 'ro', lazy => 1, builder => '_build_bag',); has fl => (is => 'ro', lazy => 1, default => sub {"*"}); sub _build_bag { my $self = $_[0]; Catmandu::Store::Solr->new( url => $self->url, bag_field => $self->bag_field, id_field => $self->id_field )->bag($self->bag()); } sub generator { my ($self) = @_; return sub { state $start = 0; state $limit = 100; state $total = 100; state $hits = []; unless (scalar(@$hits)) { return if $start >= $total; my $res = $self->_bag()->search( query => $self->query, fq => $self->fq, start => $start, limit => $limit, fl => $self->fl, facet => "false", spellcheck => "false", sort => $self->id_field() . " asc" ); $total = $res->total; $hits = $res->hits(); $start += $limit; } shift(@$hits); } } sub count { my ($self) = @_; $self->_bag()->search( query => $self->query, fq => $self->fq, limit => 0, facet => "false", spellcheck => "false" )->total(); } =head1 NAME Catmandu::Importer::Solr - Catmandu module to import data from a Solr endpoint =head1 SYNOPSIS # From the command line $ catmandu convert Solr --url "http://localhost:8983/solr" --query "type:book" # From perl use Catmandu; my %attrs = ( url => "http://localhost:8983/solr", query => 'type:book', bag_field => '_bag', id_field => '_id' ); my $importer = Catmandu->importer('Solr',%attrs); $importer->each(sub { my $row_hash = shift; ... }); =head1 AUTHOR Nicolas Franck, C<< nicolas.franck at ugent.be >> =head1 SEE ALSO L, L , L =cut 1; Solr000755001750001750 013541102541 21310 5ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/StoreBag.pm100644001750001750 1514013541102541 22520 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/Store/Solrpackage Catmandu::Store::Solr::Bag; use Catmandu::Sane; use Catmandu::Util qw(:is); use Carp qw(confess); use Catmandu::Hits; use Catmandu::Store::Solr::Searcher; use Catmandu::Store::Solr::CQL; use Catmandu::Error; use Moo; use MooX::Aliases; our $VERSION = "0.0304"; with 'Catmandu::Bag'; with 'Catmandu::CQLSearchable'; with 'Catmandu::Buffer'; has cql_mapping => (is => 'ro'); has bag_key => (is => 'lazy', alias => 'bag_field'); sub _build_bag_key { $_[0]->store->bag_key; } sub generator { my ($self) = @_; my $store = $self->store; my $name = $self->name; my $limit = $self->buffer_size; my $bag_field = $self->bag_field; my $query = qq/$bag_field:"$name"/; sub { state $start = 0; state $hits; unless ($hits && @$hits) { $hits = $store->solr->search( $query, { start => $start, rows => $limit, defType => "lucene", facet => "false", spellcheck => "false" } )->content->{response}{docs}; $start += $limit; } my $hit = shift(@$hits) || return; $self->map_fields($hit); $hit; }; } sub count { my ($self) = @_; my $name = $self->name; my $bag_field = $self->bag_field; my $res = $self->store->solr->search( qq/$bag_field:"$name"/, { rows => 0, facet => "false", spellcheck => "false", defType => "lucene", } ); $res->content->{response}{numFound}; } sub get { my ($self, $id) = @_; my $name = $self->name; my $id_field = $self->id_field; my $bag_field = $self->bag_field; my $res = $self->store->solr->search( qq/$bag_field:"$name" AND $id_field:"$id"/, { rows => 1, facet => "false", spellcheck => "false", defType => "lucene", } ); my $hit = $res->content->{response}{docs}->[0] || return; $self->map_fields($hit); $hit; } sub add { my ($self, $data) = @_; my $bag_field = $self->bag_field; my @fields = (WebService::Solr::Field->new($bag_field => $self->name)); for my $key (keys %$data) { next if $key eq $bag_field; my $val = $data->{$key}; if (is_array_ref($val)) { is_value($_) && push @fields, WebService::Solr::Field->new($key => $_) foreach @$val; } elsif (is_value($val)) { push @fields, WebService::Solr::Field->new($key => $val); } } $self->buffer_add(WebService::Solr::Document->new(@fields)); if ($self->buffer_is_full) { $self->commit; } } sub delete { my ($self, $id) = @_; my $name = $self->name; my $id_field = $self->id_field; my $bag_field = $self->bag_field; $self->store->solr->delete_by_query( qq/$bag_field:"$name" AND $id_field:"$id"/); } sub delete_all { my ($self) = @_; my $name = $self->name; my $bag_field = $self->bag_field; $self->store->solr->delete_by_query(qq/$bag_field:"$name"/); } sub delete_by_query { my ($self, %args) = @_; my $name = $self->name; my $bag_field = $self->bag_field; $self->store->solr->delete_by_query( qq/$bag_field:"$name" AND ($args{query})/); } sub commit { my ($self) = @_; my $solr = $self->store->solr; my $err; if ($self->buffer_used) { eval {$solr->add($self->buffer)} or push @{$err ||= []}, $@; $self->clear_buffer; } unless ($self->store->{_tx}) { eval {$solr->commit} or push @{$err ||= []}, $@; } if (defined $err && $self->store->on_error eq 'throw') { Catmandu::Error->throw($err->[0]); } } sub search { my ($self, %args) = @_; my $query = delete $args{query}; my $start = delete $args{start}; my $limit = delete $args{limit}; my $bag = delete $args{reify}; my $name = $self->name; my $id_field = $self->id_field; my $bag_field = $self->bag_field; my $bag_fq = qq/{!type=lucene}$bag_field:"$name"/; if ($args{fq}) { if (is_array_ref($args{fq})) { $args{fq} = [$bag_fq, @{$args{fq}}]; } else { $args{fq} = [$bag_fq, $args{fq}]; } } else { $args{fq} = $bag_fq; } my $res = $self->store->solr->search($query, {%args, start => $start, rows => $limit}); my $set = $res->content->{response}{docs}; if ($bag) { $set = [map {$bag->get($_->{$id_field})} @$set]; } else { $self->map_fields($_) for (@$set); } my $hits = Catmandu::Hits->new( { limit => $limit, start => $start, total => $res->content->{response}{numFound}, hits => $set, } ); if ($res->facet_counts) { $hits->{facets} = $res->facet_counts; } if ($res->spellcheck) { $hits->{spellcheck} = $res->spellcheck; } if ($res->content->{highlighting}) { $hits->{highlighting} = $res->content->{highlighting}; } $hits; } sub searcher { my ($self, %args) = @_; Catmandu::Store::Solr::Searcher->new(%args, bag => $self); } sub translate_sru_sortkeys { my ($self, $sortkeys) = @_; join(',', grep {defined $_} map {$self->_translate_sru_sortkey($_)} split /\s+/, $sortkeys); } sub _translate_sru_sortkey { my ($self, $sortkey) = @_; my ($field, $schema, $asc) = split /,/, $sortkey; $field || return; if (my $map = $self->cql_mapping) { $field = lc $field; $field =~ s/(?<=[^_])_(?=[^_])//g if $map->{strip_separating_underscores}; $map = $map->{indexes} || return; $map = $map->{$field} || return; $map->{sort} || return; if (ref $map->{sort} && $map->{sort}{field}) { $field = $map->{sort}{field}; } elsif (ref $map->{field}) { $field = $map->{field}->[0]; } elsif ($map->{field}) { $field = $map->{field}; } } $asc //= 1; "${field} " . ($asc ? "asc" : "desc"); } sub translate_cql_query { my ($self, $query) = @_; Catmandu::Store::Solr::CQL->new(mapping => $self->cql_mapping) ->parse($query); } sub normalize_query { $_[1] || "{!type=lucene}*:*"; } sub map_fields { my ($self, $item) = @_; delete $item->{$self->bag_field}; } =head1 SEE ALSO L, L =cut 1; CQL.pm100644001750001750 2153213541102541 22450 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/Store/Solrpackage Catmandu::Store::Solr::CQL ; #TODO see Catmandu::Store::ElasticSearch::CQL use Catmandu::Sane; use CQL::Parser; use Carp qw(confess); use Catmandu::Util qw(:is require_package); use Moo; with 'Catmandu::Logger'; our $VERSION = "0.0304"; has parser => (is => 'ro', lazy => 1, builder => '_build_parser'); has mapping => (is => 'ro'); my $any_field = qr'^(srw|cql)\.(serverChoice|anywhere)$'i; my $match_all = qr'^(srw|cql)\.allRecords$'i; my $distance_modifier = qr'\s*\/\s*distance\s*<\s*(\d+)'i; my $reserved = qr'[\+\-\&\|\!\(\)\{\}\[\]\^\"\~\*\?\:\\]'; sub _build_parser { CQL::Parser->new; } sub parse { my ($self, $query) = @_; $self->log->debug("cql query: $query"); my $node = eval {$self->parser->parse($query)} or do { my $error = $@; $self->log->error("cql error: $error"); die "cql error: $error"; }; my $solr_query = $self->visit($node); $self->log->debug("solr query: $solr_query"); $solr_query; } sub escape_term { my $term = $_[0]; $term =~ s/($reserved)/\\$1/g; $term; } sub quote_term { my $term = $_[0]; $term = qq("$term") if $term =~ /\s/; $term; } sub visit { my ($self, $node) = @_; my $mapping = $self->mapping; my $indexes = $mapping ? $mapping->{indexes} : undef; if ($node->isa('CQL::TermNode')) { my $term = escape_term($node->getTerm); if ($term =~ $match_all) { return "*:*"; } my $qualifier = $node->getQualifier; my $relation = $node->getRelation; my @modifiers = $relation->getModifiers; my $base = lc $relation->getBase; if ($base eq 'scr') { if ($mapping && $mapping->{default_relation}) { $base = $mapping->{default_relation}; } else { $base = '='; } } #default field if ($qualifier =~ $any_field) { #set default field explicitely if ($mapping && $mapping->{default_index}) { $qualifier = $mapping->{default_index}; } #make solr decide what the default field should be else { $qualifier = ""; } } #field search: new way if ($indexes) { #empty qualifier: Solr should decide how to query if (is_string($qualifier)) { #change qualifier $qualifier = lc $qualifier; my $old_qualifier = $qualifier; $qualifier =~ s/(?<=[^_])_(?=[^_])//g if $mapping->{strip_separating_underscores}; unless ($qualifier eq $old_qualifier) { $self->log->debug( "value of qualifier '$old_qualifier' reset to '$qualifier' because of setting 'strip_separating_underscores'" ); } my $q_mapping = $indexes->{$qualifier} or confess "cql error: unknown index $qualifier"; $q_mapping->{op}->{$base} or confess "cql error: relation $base not allowed"; my $op = $q_mapping->{op}->{$base}; $old_qualifier = $qualifier; if (ref $op && $op->{field}) { $qualifier = $op->{field}; } elsif ($q_mapping->{field}) { $qualifier = $q_mapping->{field}; } unless ($qualifier eq $old_qualifier) { $self->log->debug( "value of qualifier '$old_qualifier' reset to '$qualifier' because of field mapping" ); } #add solr ':' $qualifier = "$qualifier:"; #change term using filters my $filters; if (ref $op && $op->{filter}) { $filters = $op->{filter}; } elsif ($q_mapping->{filter}) { $filters = $q_mapping->{filter}; } if ($filters) { for my $filter (@$filters) { if ($filter eq 'lowercase') { $self->log->debug( "term '$term' filtered to lowercase"); $term = lc $term; } } } #change term using callbacks if (ref $op && $op->{cb}) { my ($pkg, $sub) = @{$op->{cb}}; $self->log->debug( "term '$term' changed to ${pkg}->${sub}"); $term = require_package($pkg)->$sub($term); } elsif ($q_mapping->{cb}) { my ($pkg, $sub) = @{$q_mapping->{cb}}; $self->log->debug( "term '$term' changed to ${pkg}->${sub}"); $term = require_package($pkg)->$sub($term); } } } #field search: old way else { #add solr ':' $qualifier = "$qualifier:" if is_string $qualifier; } if ($base eq '=' or $base eq 'scr') { $term = quote_term($term); for my $m (@modifiers) { if ($m->[1] eq 'fuzzy') { return "$qualifier$term~"; } } return $qualifier . $term; } elsif ($base eq '<') { $term = quote_term($term); return $qualifier . "{* TO $term}"; } elsif ($base eq '>') { $term = quote_term($term); return $qualifier . "{$term TO *}"; } elsif ($base eq '<=') { $term = quote_term($term); return $qualifier . "[* TO $term]"; } elsif ($base eq '>=') { $term = quote_term($term); return $qualifier . "[$term TO *]"; } elsif ($base eq '<>') { $term = quote_term($term); return "-$qualifier$term"; } elsif ($base eq 'exact') { return $qualifier . quote_term($term); } elsif ($base eq 'all') { my @terms = split /\s+/, $term; if (@terms == 1) { return $qualifier . $term; } $term = join ' ', map {"+$_"} @terms; if ($qualifier) { return "$qualifier($term)"; } return $term; } elsif ($base eq 'any') { $term = join ' OR ', map {$qualifier . $_} split /\s+/, $term; return "( $term)"; } elsif ($base eq 'within') { my @range = split /\s+/, $term; if (@range == 1) { return $qualifier . $term; } else { return $qualifier . "[$range[0] TO $range[1]]"; } } else { return $qualifier . quote_term($term); } } #TODO: apply cql_mapping elsif ($node->isa('CQL::ProxNode')) { my $distance = 1; my $qualifier = $node->left->getQualifier; my $term = escape_term( join(' ', $node->left->getTerm, $node->right->getTerm)); if (my ($n) = $node->op =~ $distance_modifier) { $distance = $n if $n > 1; } if ($qualifier =~ $any_field) { return qq("$term"~$distance); } else { return qq($qualifier:"$term"~$distance); } } elsif ($node->isa('CQL::BooleanNode')) { my $lft = $node->left; my $rgt = $node->right; my $lft_q = $self->visit($lft); my $rgt_q = $self->visit($rgt); $lft_q = "( $lft_q)" unless $lft->isa('CQL::TermNode') || $lft->isa('CQL::ProxNode'); $rgt_q = "( $rgt_q)" unless $rgt->isa('CQL::TermNode') || $rgt->isa('CQL::ProxNode'); return join ' ', $lft_q, uc $node->op, $rgt_q; } } 1; =head1 NAME Catmandu::Store::Solr::CQL - Converts a CQL query string to a Solr query string =head1 SYNOPSIS $solr_query_string = Catmandu::Store::Solr::CQL->parse($cql_query_string); =head1 DESCRIPTION This package currently parses most of CQL 1.1: and or not prox prox/distance<$n srw.allRecords srw.serverChoice srw.anywhere cql.allRecords cql.serverChoice cql.anywhere = scr =/fuzzy scr/fuzzy < > <= >= <> exact all any within =head1 METHODS =head2 parse Parses the given CQL query string with L and converts it to a Solr query string. =head2 visit Converts the given L to a Solr query string. =head1 TODO support cql 1.2, more modifiers (esp. masked), sortBy, encloses =head1 SEE ALSO L. =cut Searcher.pm100644001750001750 450213541102541 23543 0ustar00nsteenlansteenla000000000000Catmandu-Solr-0.0304/lib/Catmandu/Store/Solrpackage Catmandu::Store::Solr::Searcher; use Catmandu::Sane; use Moo; our $VERSION = "0.0304"; with 'Catmandu::Iterable'; has bag => (is => 'ro', required => 1); has query => (is => 'ro', required => 1); has start => (is => 'ro', required => 1); has limit => (is => 'ro', required => 1); has sort => (is => 'ro', required => 0); has total => (is => 'ro'); has fl => (is => 'ro', lazy => 1, default => sub {"*"}); sub generator { my ($self) = @_; my $store = $self->bag->store; my $name = $self->bag->name; my $limit = $self->limit; my $query = $self->query; my $bag_field = $self->bag->bag_field; my $fq = qq/{!type=lucene}$bag_field:"$name"/; sub { state $start = $self->start; state $total = $self->total; state $hits; if (defined $total) { return unless $total; } unless ($hits && @$hits) { if ($total && $limit > $total) { $limit = $total; } $hits = $store->solr->search( $query, { start => $start, rows => $limit, fq => $fq, sort => $self->sort, fl => $self->fl, facet => "false", spellcheck => "false" } )->content->{response}{docs}; $start += $limit; } if ($total) { $total--; } my $hit = shift(@$hits) || return; $self->bag->map_fields($hit); $hit; }; } sub slice { my ($self, $start, $total) = @_; $start //= 0; $self->new( bag => $self->bag, query => $self->query, start => $self->start + $start, limit => $self->limit, sort => $self->sort, total => $total, ); } sub count { my ($self) = @_; my $name = $self->bag->name; my $bag_field = $self->bag->bag_field; my $res = $self->bag->store->solr->search( $self->query, { rows => 0, fq => qq/{!type=lucene}$bag_field:"$name"/, facet => "false", spellcheck => "false" } ); $res->content->{response}{numFound}; } 1;