groonga-client-rails 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/Gemfile +21 -0
- data/README.md +57 -0
- data/Rakefile +44 -0
- data/doc/text/lgpl-2.1.txt +502 -0
- data/doc/text/news.md +5 -0
- data/groonga-client-rails.gemspec +52 -0
- data/lib/groonga-client-rails.rb +23 -0
- data/lib/groonga/client/rails/fixture.rb +35 -0
- data/lib/groonga/client/rails/groonga_server_runner.rb +164 -0
- data/lib/groonga/client/rails/spec_helper.rb +39 -0
- data/lib/groonga/client/rails/test_helper.rb +39 -0
- data/lib/groonga/client/rails/version.rb +23 -0
- data/lib/groonga/client/railtie.rb +70 -0
- data/lib/groonga/client/searcher.rb +165 -0
- data/lib/groonga/client/searcher/error.rb +37 -0
- data/lib/groonga/client/searcher/raw_request.rb +85 -0
- data/lib/groonga/client/searcher/schema.rb +74 -0
- data/lib/groonga/client/searcher/schema_synchronizer.rb +137 -0
- data/lib/groonga/client/searcher/select.rb +18 -0
- data/lib/groonga/client/searcher/select/request.rb +266 -0
- data/lib/groonga/client/searcher/select/result_set.rb +117 -0
- data/lib/groonga/client/searcher/source.rb +59 -0
- data/test/apps/rails4-mongoid/Gemfile +50 -0
- data/test/apps/rails4-mongoid/Gemfile.lock +190 -0
- data/test/apps/rails4-mongoid/README.rdoc +28 -0
- data/test/apps/rails4-mongoid/Rakefile +6 -0
- data/test/apps/rails4-mongoid/app/assets/javascripts/application.js +16 -0
- data/test/apps/rails4-mongoid/app/assets/javascripts/posts.coffee +3 -0
- data/test/apps/rails4-mongoid/app/assets/stylesheets/application.css +15 -0
- data/test/apps/rails4-mongoid/app/assets/stylesheets/posts.scss +3 -0
- data/test/apps/rails4-mongoid/app/assets/stylesheets/scaffolds.scss +73 -0
- data/test/apps/rails4-mongoid/app/controllers/application_controller.rb +5 -0
- data/test/apps/rails4-mongoid/app/controllers/posts_controller.rb +74 -0
- data/test/apps/rails4-mongoid/app/helpers/application_helper.rb +2 -0
- data/test/apps/rails4-mongoid/app/helpers/posts_helper.rb +2 -0
- data/test/apps/rails4-mongoid/app/models/post.rb +12 -0
- data/test/apps/rails4-mongoid/app/searchers/application_searcher.rb +2 -0
- data/test/apps/rails4-mongoid/app/searchers/posts_searcher.rb +16 -0
- data/test/apps/rails4-mongoid/app/views/layouts/application.html.erb +14 -0
- data/test/apps/rails4-mongoid/app/views/posts/_form.html.erb +25 -0
- data/test/apps/rails4-mongoid/app/views/posts/edit.html.erb +6 -0
- data/test/apps/rails4-mongoid/app/views/posts/index.html.erb +29 -0
- data/test/apps/rails4-mongoid/app/views/posts/index.json.jbuilder +4 -0
- data/test/apps/rails4-mongoid/app/views/posts/new.html.erb +5 -0
- data/test/apps/rails4-mongoid/app/views/posts/show.html.erb +14 -0
- data/test/apps/rails4-mongoid/app/views/posts/show.json.jbuilder +1 -0
- data/test/apps/rails4-mongoid/bin/bundle +3 -0
- data/test/apps/rails4-mongoid/bin/rails +4 -0
- data/test/apps/rails4-mongoid/bin/rake +4 -0
- data/test/apps/rails4-mongoid/bin/setup +29 -0
- data/test/apps/rails4-mongoid/config.ru +4 -0
- data/test/apps/rails4-mongoid/config/application.rb +32 -0
- data/test/apps/rails4-mongoid/config/boot.rb +3 -0
- data/test/apps/rails4-mongoid/config/environment.rb +5 -0
- data/test/apps/rails4-mongoid/config/environments/development.rb +38 -0
- data/test/apps/rails4-mongoid/config/environments/production.rb +76 -0
- data/test/apps/rails4-mongoid/config/environments/test.rb +42 -0
- data/test/apps/rails4-mongoid/config/groonga_client.yml +22 -0
- data/test/apps/rails4-mongoid/config/initializers/assets.rb +11 -0
- data/test/apps/rails4-mongoid/config/initializers/backtrace_silencers.rb +7 -0
- data/test/apps/rails4-mongoid/config/initializers/cookies_serializer.rb +3 -0
- data/test/apps/rails4-mongoid/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/apps/rails4-mongoid/config/initializers/inflections.rb +16 -0
- data/test/apps/rails4-mongoid/config/initializers/mime_types.rb +4 -0
- data/test/apps/rails4-mongoid/config/initializers/session_store.rb +3 -0
- data/test/apps/rails4-mongoid/config/initializers/wrap_parameters.rb +9 -0
- data/test/apps/rails4-mongoid/config/locales/en.yml +23 -0
- data/test/apps/rails4-mongoid/config/mongoid.yml +142 -0
- data/test/apps/rails4-mongoid/config/routes.rb +57 -0
- data/test/apps/rails4-mongoid/config/secrets.yml +22 -0
- data/test/apps/rails4-mongoid/db/seeds.rb +7 -0
- data/test/apps/rails4-mongoid/log/development.log +764 -0
- data/test/apps/rails4-mongoid/log/test.log +15736 -0
- data/test/apps/rails4-mongoid/public/404.html +67 -0
- data/test/apps/rails4-mongoid/public/422.html +67 -0
- data/test/apps/rails4-mongoid/public/500.html +66 -0
- data/test/apps/rails4-mongoid/public/favicon.ico +0 -0
- data/test/apps/rails4-mongoid/public/robots.txt +5 -0
- data/test/apps/rails4-mongoid/test/controllers/posts_controller_test.rb +51 -0
- data/test/apps/rails4-mongoid/test/factories/posts.rb +6 -0
- data/test/apps/rails4-mongoid/test/models/post_test.rb +9 -0
- data/test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb +119 -0
- data/test/apps/rails4-mongoid/test/test_helper.rb +9 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/-Xhj-Mbb82rk571sDsQxrdCywGX36vsenBH1RUlK-LY.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/0f_MbWM7kHYaEii2fU46RtcPM1c5AvKKzZXw_HiM0CE.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/2PZE0O2lwq-MOTwxKTZxLxQwY8_QyhrbRsthl3Lc4lQ.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/5dV_yE4FDckg8xSumojLvTuflbNyhpApq7LPOy-e1X0.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/7efkcYvlMpIQU8kuDy1jAKDLjakVGoH6N5V-AuzuTZc.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/8Zm1d9-lBPsGG_HUw8FP2OCCVucGDVhWAOGaopvOdss.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/9B_fDWO-7yTtWLP7C6kgtW5LN2zlpAqr1km-1jSQx2w.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/9X7nmZiJ1BxgVp80vJFjKw2uuEfdS1ik3B66O4_iWPo.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/APY89OAPJx9A3D3xcCoktvEvQUs7NcWChYXnjjjPzz0.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/CWMzfW8FmEfR6gB4BwariPLjTZTtLc4bCVc0r0m2VV4.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/C_ZXB0e-P6-9Ty60eBWeAui5uzzA0NzDW8amqmtTk9g.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Cg1VzEm4v80ed-e0X3WGAHJWYiC_ybnfBrRrIvltPXc.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Cjhm36F4tzUHdc1e0Bho51N0H4HYybVTrxTmbtiqih4.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/DSOLSc6A5RVSmvM415eEWAWG_AgOvZcLZOXQjsXyWQA.cache +2 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/EBtbhweQl74JQNkwFL3ahZH_9x44ceqa9hOT8lQ_SfM.cache +2 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/EQICjEOYeXNTngMqEgET0L1SuE4AVuoKyJgio4ks43A.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Edyy4hZsoEraZijGtQOEBXtG2121KJUoZeUxxPjVoD8.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/HfA_T6XraGo2Ny22jLyDJkU33FwcVIBOxUIXJAfTZnw.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/I-oUhfEICgXeCJ30YmQbpoYtgGAJK0-Pql8kOvfHUIs.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ITBgBGR9-8E08Y63Vjo65c8DzPESTHJuYCXZp0y6k_I.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/JImLmTmbMkDKlN30hse8U-u0IV8hvfdebOL3EFz71FE.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Joxxq6tZo5Z61fNSWcPCGgCyehta1sNKXM0i53ziK0o.cache +2 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/KPHQh44WoGRX0SuVORNxUqq129kPRQ4Sfwr0MgBGTWg.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/MQWJrWW-vCooFa9lpB2Z7KDIE9ilL54d5Sf_SRtQhTM.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Olyga_OJ5Sz5He_RVZLO_BraSHgGvt9BG0ORecSD4A4.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/OoG10cMLeO2eGZxk483Gx75vNDQz7Id8sxVt3g26jQE.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/P2sNuT6usNXi8DQFFQ2SMByy1v98zmNdwdx6wduUQDg.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Pm3ENYpCrQMOJGd-d8lACN_nbGZWiivq_KyPLJoD9Xk.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/PrxeUFTxE6CmNlJ4CQLxcmAQKwOGBKNCFYluKNhVPdI.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/PuNKoh-EB-UU-NnPetIEhS3emExlV586tfFJnBFhaxo.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/QyBzeHR44VD1fMDrJcMOaVyyn1xgHnmhPX2VL3R6EdE.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/QyU_Bdj5YdiIQef2XhSDP5MQf7l3u_A81md3KFPQ2N4.cache +2 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/R9YbLXVmFuZvXntmUsVoP9gdFgZaoKuww_0l-ulu_Sw.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/RbDvgwCB1ggHONj2Gglg9cljN_KExx-gHiSiItOFBVw.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Rkd99KDYtUtVb3U566M9L4YD2Kh-Qp147dHVmyXnDhg.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Sin6bEoASrNa45108CpfgF2jcifz-KpbsvvZJtqVZ68.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/SuhtC6f7E2-1SXl4bkRvOKqhzFKTjPvbglVtjbjV6WQ.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/WDXpPe61HDYBIqMMzcYJWujunl4HLJBvhn0OOP1yQso.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Y2HHx2PygDVpbc258EY6XyZq_3ocHy5fEq-5UHSNfh0.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/Zot5Dwe9yQ1wvCpegdXXjC8DUGHfH1xLxerosBjUsns.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ZwSejSAeaXOqaevCGNDw6GT4jzf6iGxiDfUGqtjYqxE.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/bsYyBqujQ9Bb_NkqKjx8J9lC8MPb-Ed59b__aV46Bic.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/cnfLEWE92uT-WDII157E3Z5XISKK99q6__D2IiTRhOM.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/cnk28xBZ2NhIHyeh4bImJu1D8MsQZksGaVeYZSDL-Mw.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/cyuaVF0ZckKku_VGsQYOntnl3oNlSP381WW5VhCMbE4.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ee9ZqYM3D8GORlAyhQhVVtyNcEArBAXuuAcPhnfTNT8.cache +5 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/fQe7NSWabAv2wB6jtw0Tjp5CT06xwpla822ipJiUCy0.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/fme939QD_yb-kVcNE40VAdyOZYRTHgZCxYLVDZLuzF0.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/gl7MP7d46hviHXVnGFYORtcWessT58E75rSQUFjfiII.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/hHOboG408ksat1oQaCWVNxzf-FIyTREQFXHdFZurlZQ.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/i5GV8tvuWRKqi-plBB0bdaAqfdW_CpIMlk_3qZYyask.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ioEvK0rblqqEotrMItm0VrKhWOXnC3vwC-CIU9UCZEg.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ivzms341pOxkVrOTXM3Yog9cLwq3SmsXcwGMbRGmM6s.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/j0l28m8jfc6vnBWrkD0zWt2ELCJfEOMeEjW0Q4GADNY.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/jPuyl--LQd6DGNNoxSkPhBGx_ul_1kfka93EDJmnc8c.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/jaYo3RHF_E7SipTqBJcsnR0JcOOa0rFpEHmp3nLDrQI.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/kSkCWaAJCcTgZ_AhrRCjZhNtkE12cubiq70uNtditqk.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/mXFXPQpdpe6VdLyG_ATkrFvhK-DzKohwq6B2GOQo9R8.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/q2eC-e4sz4yzY37JZQfdjar0jjp4v7rHuGin5JEKV7Q.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/s6DK-YkFoxYJMKXt21m9PdMtZi3TJhRoHIi0R5i69Zs.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/sLDAakEn7_JrPiyZe0ZUsCLDnaTAal-5HajraaAgdhE.cache +2 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/teXpzhiur3Mnn2KsTY8q4HhEqpbdmKBfBW2iS5-MvUI.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/tgZjQMFX0Ebx2i8ovlwnvwULhvrhFNJLAIQjUNZN1RM.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/tihMlIo90U72qN2BzGajipIJOWppg8OIJuVnnluwVJM.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/vpD8YcdUFmWVggV1ANqLIWcTbMItiGv1aOUd3i_Sf_w.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/wBoZhq66JcV9m6-FvOoZ-Q3Cy9mgT-ynjPWZWZdafLw.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/wTWJ6pQBopl4RdCt1QzngFCI6BQsl97QiZJO8bkGZd4.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/wjVbFqqSw39d-ryprJ1NYmKProunHG47jEI6RFHcLM4.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/wm5Vu6DEN0ZExnKV0oAADsKfEn3yvO4aBQJwp6b8FbU.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/x0qPZqkeQj_x2GoHegxhwuHhPMrz8iHGdALgbSEtYB0.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/xESXQaQoarUInNLmS7yPvF7D9FlSfaR8n8CsT6vIfmU.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/xJpeFclkEQS028sCHKPl9C6EyiAcTgUW_lBAqjRuP_c.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/yinyMcV6eKC4p76ZeetFBkRq8qYD5b8fWOHbukaCUNk.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/ytg8J2fjBhc978nkpdl0f5cBPdcKpig523h4O4eN664.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/z5Cl2oKorg00CGt089PLdPdoE1ELvsz4CdtXnlUk7KM.cache +0 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/z6uhOy1uoRnC6c9iKrzc1vRqGH1KQrhArDe51rZL1_k.cache +1 -0
- data/test/apps/rails4-mongoid/tmp/cache/assets/sprockets/v3.0/zIFdfoc8nFjrQhTXHyamSnNA6CVVrOcsP4qfDQhOcVI.cache +1 -0
- data/test/run-test.rb +43 -0
- data/test/unit/run-test.rb +25 -0
- data/test/unit/searcher/select/filter_parameter_test.rb +99 -0
- data/test/unit/searcher/select/match_columns_parameter_test.rb +59 -0
- data/test/unit/searcher/select/output_columns_parameter_test.rb +68 -0
- data/test/unit/searcher/select/sortby_parameter_test.rb +63 -0
- data/test/unit/test_helper.rb +19 -0
- metadata +480 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "groonga/client/searcher/select/request"
|
18
|
+
require "groonga/client/searcher/select/result_set"
|
@@ -0,0 +1,266 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "active_support/core_ext/object/blank"
|
18
|
+
|
19
|
+
require "groonga/client/searcher/raw_request"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
class Client
|
23
|
+
class Searcher
|
24
|
+
module Select
|
25
|
+
class Request < RawRequest
|
26
|
+
def initialize(table_or_parameters)
|
27
|
+
if table_or_parameters.respond_to?(:to_parameters)
|
28
|
+
parameters = table_or_parameters
|
29
|
+
else
|
30
|
+
table_name = table_or_parameters
|
31
|
+
parameters = RequestParameter.new(:table, table_name)
|
32
|
+
end
|
33
|
+
super("select", parameters)
|
34
|
+
end
|
35
|
+
|
36
|
+
def result_set
|
37
|
+
@result_set ||= ResultSet.new(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
def match_columns(value)
|
41
|
+
add_parameter(OverwriteMerger,
|
42
|
+
MatchColumnsParameter.new(value))
|
43
|
+
end
|
44
|
+
|
45
|
+
def query(value)
|
46
|
+
add_parameter(QueryMerger,
|
47
|
+
RequestParameter.new(:query, value))
|
48
|
+
end
|
49
|
+
|
50
|
+
def filter(expression, values=nil)
|
51
|
+
add_parameter(FilterMerger,
|
52
|
+
FilterParameter.new(expression, values))
|
53
|
+
end
|
54
|
+
|
55
|
+
def output_columns(value)
|
56
|
+
add_parameter(OverwriteMerger,
|
57
|
+
OutputColumnsParameter.new(value))
|
58
|
+
end
|
59
|
+
|
60
|
+
def sortby(value)
|
61
|
+
add_parameter(OverwriteMerger,
|
62
|
+
SortbyParameter.new(value))
|
63
|
+
end
|
64
|
+
alias_method :sort, :sortby
|
65
|
+
|
66
|
+
def offset(value)
|
67
|
+
parameter(:offset, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
def limit(value)
|
71
|
+
parameter(:limit, value)
|
72
|
+
end
|
73
|
+
|
74
|
+
def paginate(page, per_page: 10)
|
75
|
+
page ||= 1
|
76
|
+
page = page.to_i
|
77
|
+
return self if page < 0
|
78
|
+
|
79
|
+
offset(per_page * page).limit(per_page)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def create_request(parameters)
|
84
|
+
self.class.new(parameters)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# @private
|
89
|
+
class QueryMerger < ParameterMerger
|
90
|
+
def to_parameters
|
91
|
+
params1 = @parameters1.to_parameters
|
92
|
+
params2 = @parameters2.to_parameters
|
93
|
+
params = params1.merge(params2)
|
94
|
+
query1 = params1[:query]
|
95
|
+
query2 = params2[:query]
|
96
|
+
if query1.present? and query2.present?
|
97
|
+
params[:query] = "(#{query1}) (#{query2})"
|
98
|
+
else
|
99
|
+
params[:query] = (query1 || query2)
|
100
|
+
end
|
101
|
+
params
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# @private
|
106
|
+
class FilterMerger < ParameterMerger
|
107
|
+
def to_parameters
|
108
|
+
params1 = @parameters1.to_parameters
|
109
|
+
params2 = @parameters2.to_parameters
|
110
|
+
params = params1.merge(params2)
|
111
|
+
filter1 = params1[:filter]
|
112
|
+
filter2 = params2[:filter]
|
113
|
+
if filter1.present? and filter2.present?
|
114
|
+
params[:filter] = "(#{filter1}) && (#{filter2})"
|
115
|
+
else
|
116
|
+
params[:filter] = (filter1 || filter2)
|
117
|
+
end
|
118
|
+
params
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# @private
|
123
|
+
class MatchColumnsParameter
|
124
|
+
def initialize(match_columns)
|
125
|
+
@match_columns = match_columns
|
126
|
+
end
|
127
|
+
|
128
|
+
def to_parameters
|
129
|
+
if @match_columns.blank?
|
130
|
+
{}
|
131
|
+
else
|
132
|
+
case @match_columns
|
133
|
+
when ::Array
|
134
|
+
match_columns = @match_columns.join(", ")
|
135
|
+
when Symbol
|
136
|
+
match_columns = @match_columns.to_s
|
137
|
+
else
|
138
|
+
match_columns = @match_columns
|
139
|
+
end
|
140
|
+
{
|
141
|
+
match_columns: match_columns,
|
142
|
+
}
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# @private
|
148
|
+
class FilterParameter
|
149
|
+
def initialize(expression, values)
|
150
|
+
@expression = expression
|
151
|
+
@values = values
|
152
|
+
end
|
153
|
+
|
154
|
+
def to_parameters
|
155
|
+
if @expression.blank?
|
156
|
+
{}
|
157
|
+
else
|
158
|
+
if @values.blank?
|
159
|
+
expression = @expression
|
160
|
+
else
|
161
|
+
escaped_values = {}
|
162
|
+
@values.each do |key, value|
|
163
|
+
escaped_values[key] = escape_filter_value(value)
|
164
|
+
end
|
165
|
+
expression = @expression % escaped_values
|
166
|
+
end
|
167
|
+
{
|
168
|
+
filter: expression,
|
169
|
+
}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
def escape_filter_value(value)
|
175
|
+
case value
|
176
|
+
when Numeric
|
177
|
+
value
|
178
|
+
when TrueClass, FalseClass
|
179
|
+
value
|
180
|
+
when NilClass
|
181
|
+
"null"
|
182
|
+
when String
|
183
|
+
ScriptSyntax.format_string(value)
|
184
|
+
when Symbol
|
185
|
+
ScriptSyntax.format_string(value.to_s)
|
186
|
+
when ::Array
|
187
|
+
escaped_value = "["
|
188
|
+
value.each_with_index do |element, i|
|
189
|
+
escaped_value << ", " if i > 0
|
190
|
+
escaped_value << escape_filter_value(element)
|
191
|
+
end
|
192
|
+
escaped_value << "]"
|
193
|
+
escaped_value
|
194
|
+
when ::Hash
|
195
|
+
escaped_value = "{"
|
196
|
+
value.each_with_index do |(k, v), i|
|
197
|
+
escaped_value << ", " if i > 0
|
198
|
+
escaped_value << escape_filter_value(k.to_s)
|
199
|
+
escaped_value << ": "
|
200
|
+
escaped_value << escape_filter_value(v)
|
201
|
+
end
|
202
|
+
escaped_value << "}"
|
203
|
+
escaped_value
|
204
|
+
else
|
205
|
+
value
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# @private
|
211
|
+
class OutputColumnsParameter
|
212
|
+
def initialize(output_columns)
|
213
|
+
@output_columns = output_columns
|
214
|
+
end
|
215
|
+
|
216
|
+
def to_parameters
|
217
|
+
if @output_columns.blank?
|
218
|
+
{}
|
219
|
+
else
|
220
|
+
case @output_columns
|
221
|
+
when ::Array
|
222
|
+
output_columns = @output_columns.join(", ")
|
223
|
+
when Symbol
|
224
|
+
output_columns = @output_columns.to_s
|
225
|
+
else
|
226
|
+
output_columns = @output_columns
|
227
|
+
end
|
228
|
+
parameters = {
|
229
|
+
output_columns: output_columns,
|
230
|
+
}
|
231
|
+
if output_columns.include?("(")
|
232
|
+
parameters[:command_version] = "2"
|
233
|
+
end
|
234
|
+
parameters
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# @private
|
240
|
+
class SortbyParameter
|
241
|
+
def initialize(sortby)
|
242
|
+
@sortby = sortby
|
243
|
+
end
|
244
|
+
|
245
|
+
def to_parameters
|
246
|
+
if @sortby.blank?
|
247
|
+
{}
|
248
|
+
else
|
249
|
+
case @sortby
|
250
|
+
when ::Array
|
251
|
+
sortby = @sortby.collect(&:to_s).join(", ")
|
252
|
+
when Symbol
|
253
|
+
sortby = @sortby.to_s
|
254
|
+
else
|
255
|
+
sortby = @sortby
|
256
|
+
end
|
257
|
+
{
|
258
|
+
sortby: sortby,
|
259
|
+
}
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module Groonga
|
18
|
+
class Client
|
19
|
+
class Searcher
|
20
|
+
module Select
|
21
|
+
class ResultSet
|
22
|
+
def initialize(response)
|
23
|
+
@response = response
|
24
|
+
end
|
25
|
+
|
26
|
+
def n_hits
|
27
|
+
@response.n_hits
|
28
|
+
end
|
29
|
+
# For Kaminari
|
30
|
+
alias_method :total_count, :n_hits
|
31
|
+
|
32
|
+
# For Kaminari
|
33
|
+
def limit_value
|
34
|
+
(@response.command[:limit] || 10).to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
# For Kaminari
|
38
|
+
def offset_value
|
39
|
+
(@response.command[:offset] || 0).to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def records
|
43
|
+
@records ||= build_records
|
44
|
+
end
|
45
|
+
|
46
|
+
def sources
|
47
|
+
@sources ||= fetch_sources
|
48
|
+
end
|
49
|
+
|
50
|
+
def drilldowns
|
51
|
+
@response.drilldowns
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def build_records
|
56
|
+
@response.records.collect.with_index do |record, i|
|
57
|
+
Record.new(self, i, record)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def fetch_sources
|
62
|
+
source_ids = {}
|
63
|
+
records.collect do |record|
|
64
|
+
model_name, id = record["_key"].split(/-/, 2)
|
65
|
+
source_ids[model_name] ||= []
|
66
|
+
source_ids[model_name] << id
|
67
|
+
end
|
68
|
+
sources = {}
|
69
|
+
source_ids.each do |model_name, ids|
|
70
|
+
model_name.constantize.find(ids).each_with_index do |model, i|
|
71
|
+
sources["#{model_name}-#{ids[i]}"] = model
|
72
|
+
end
|
73
|
+
end
|
74
|
+
records.collect do |record|
|
75
|
+
sources[record["_key"]]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Record
|
80
|
+
def initialize(result_set, nth, raw_record)
|
81
|
+
@result_set = result_set
|
82
|
+
@nth = nth
|
83
|
+
@raw_record = raw_record
|
84
|
+
end
|
85
|
+
|
86
|
+
def source
|
87
|
+
@result_set.sources[@nth]
|
88
|
+
end
|
89
|
+
|
90
|
+
def [](name)
|
91
|
+
@raw_record[normalize_name(name)]
|
92
|
+
end
|
93
|
+
|
94
|
+
def method_missing(name, *args, &block)
|
95
|
+
return super unless args.empty?
|
96
|
+
return super unless @raw_record.key?(name.to_s)
|
97
|
+
|
98
|
+
self[name]
|
99
|
+
end
|
100
|
+
|
101
|
+
def respond_to_missing?(name, *args, &block)
|
102
|
+
return super unless args.empty?
|
103
|
+
return super unless @raw_record.key?(name.to_s)
|
104
|
+
|
105
|
+
@raw_record.key?(normalize_name(name))
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def normalize_name(name)
|
110
|
+
name.to_s
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module Groonga
|
18
|
+
class Client
|
19
|
+
class Searcher
|
20
|
+
class Source
|
21
|
+
attr_reader :model_class
|
22
|
+
attr_reader :columns
|
23
|
+
def initialize(schema, model_class)
|
24
|
+
@schema = schema
|
25
|
+
@model_class = model_class
|
26
|
+
@columns = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def []=(name, reader)
|
30
|
+
unless @schema.have_column?(name)
|
31
|
+
message = "unknown column name: #{name.inspect}"
|
32
|
+
available_columns = @schema.columns.keys.join(", ")
|
33
|
+
message << "available columns: [#{available_columns}]"
|
34
|
+
raise ArgumentError, message
|
35
|
+
end
|
36
|
+
@columns[name.to_s] = reader
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(name, *args, &block)
|
40
|
+
return super unless name.to_s.end_with?("=")
|
41
|
+
|
42
|
+
base_name = name.to_s[0..-2]
|
43
|
+
if @schema.have_column?(base_name)
|
44
|
+
__send__(:[]=, base_name, *args, &block)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def respond_to_missing?(name, include_private)
|
51
|
+
return super unless name.to_s.end_with?("=")
|
52
|
+
|
53
|
+
base_name = name.to_s[0..-2]
|
54
|
+
@schema.have_column?(base_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|