ãã®è¨äºã¯Groonga Advent Calendar 2014 - Qiitaã®17æ¥ã®è¨äºã§ãã
Groongaã¯ãªã¼ãã³ã½ã¼ã¹ã®ã«ã©ã ã¹ãã¢æ©è½ä»ãå ¨ææ¤ç´¢ã¨ã³ã¸ã³ã§ããRroongaãGrnMiniã使ãã¨Rubyçµç±ã§ç°¡åã«ã¢ã¯ã»ã¹ãããã¨ãåºæ¥ã¾ãã
æ¤ç´¢ç¨ã¯ã¨ãªã工夫ãã¦ãã¼ã¿ãè²ã ãªè§åº¦ããçºããã®ã¯æ¥½ããã®ã§ãããå ¨ææ¤ç´¢ãããã¹ã¯ãªãããæ¸ãæã«é¢åãªã®ã¯å ¨ææ¤ç´¢ç¨ã®ãã¼ã¿ãã¼ã¹ãç¨æããé¨åã§ãã
ããã§ã
- ãã¼ã¿ãã¼ã¹ã®ä½æã¯ä»ã®ã¢ããªã±ã¼ã·ã§ã³ã使ã£ã¦è¡ã
- æ¤ç´¢é¨åã ããèªåã§æ¸ã
ã¨ããã¢ã¤ãã¢ãæãã¤ãã¾ããã
Milkodeã®ã¤ã³ã¹ãã¼ã«
ä»åã¯ã½ã¼ã¹ã³ã¼ãæ¤ç´¢ã¨ã³ã¸ã³ã®Milkodeã使ãã¾ããã½ã¼ã¹ã³ã¼ãæ¤ç´¢ã¨ã³ã¸ã³ã¨è© ã£ã¦ãã¾ããæ¬è³ªçã«ã¯ãã¡ã¤ã«ãã¼ã¿ãã¼ã¹ãªã®ã§å¥½ããªãã¡ã¤ã«ç¾¤ãç»é²ãã¦Rubyã¹ã¯ãªããããæ¤ç´¢ãããã¨ãã£ããã¨ãåºæ¥ã¾ãã
Milkode - è¡æåã®ã½ã¼ã¹ã³ã¼ãæ¤ç´¢ã¨ã³ã¸ã³
$ gem install milkode
試ãã«railsã®ã½ã¼ã¹ã³ã¼ãã§ã足ãã¦ããã¾ãããã
$ milk init $ milk add -p git https://github.com/rails/rails.git
ãã¼ã¿ãã¼ã¹ãéã
ãã¼ã¿ãã¼ã¹ãéãã¦æ¤ç´¢ãã¦ã¿ã¾ãã/Users/ongaeshi/.milkode
ã¯é©å®ç½®ãæãã¦ä¸ããã
# -*- coding: utf-8 -*- require 'groonga' # ãã¼ã¿ãã¼ã¹ãéã Groonga::Database.open("/Users/ongaeshi/.milkode/db/milkode.db") # ãã¼ãã«ãéã documents = Groonga["documents"] p documents.count # => ç»é²ããã¦ããã¬ã³ã¼ãã®æ°: 2733 # ã¬ã³ã¼ãã®å 容ãèªã path = "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/relation/calculations.rb" p documents[path].path # => 絶対ãã¹: "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/relation/calculations.rb" p documents[path].package # => ããã±ã¼ã¸å: "rails" p documents[path].restpath # => ããã±ã¼ã¸åããå ã®ãã¡ã¤ã«ãã¹: "activerecord/lib/active_record/relation/calculations.rb" p documents[path].content # => ãã¡ã¤ã«ã®å 容: "module ActiveRecord\n module Calculations..." p documents[path].timestamp # => ã¿ã¤ã ã¹ã¿ã³ã: 2014-12-18 02:25:11 +0900 p documents[path].suffix # => æ¡å¼µå: "rb" puts # 'column:@''ã¯é¨åä¸è´ã'column:'ã¯å®å ¨ä¸è´ # http://groonga.org/ja/docs/reference/grn_expr/query_syntax.html # ãã¡ã¤ã«å 容ã«ä»¥ä¸ã®ãã¼ã¯ã¼ããå ¨ã¦å«ãã¬ã³ã¼ããæ¢ã documents.select("content:@def content:@pluck").each do |record| p record.path end puts # å 容ã«'def','pluck'ãå«ã¿æ¡å¼µå'md'ã®ãã® documents.select("content:@def content:@pluck suffix:md").each do |record| p record.path end puts # ããã±ã¼ã¸å'rails'ã§æ¡å¼µå'rdoc' documents.select("package:rails suffix:rdoc").each do |record| p record.path end puts # å 容ã«'pluck'ãå«ã¿ãã¡ã¤ã«ãã¹ã«'cases'ãå«ããã® documents.select("content:@pluck restpath:@cases").each do |record| p record.path end puts
å®è¡çµæ
2733 "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/relation/calculations.rb" "rails" "activerecord/lib/active_record/relation/calculations.rb" "module ActiveRecord\n module Calculations\n ..." 2014-12-18 02:25:11 +0900 "rb" "/Users/ongaeshi/.milkode/packages/git/rails/actionview/lib/action_view/routing_url_for.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/associations/collection_association.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/null_relation.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/querying.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/relation/calculations.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/relation/finder_methods.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/schema_migration.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/lib/active_record/scoping/named.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_many_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/base_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/calculations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relation/merging_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relation_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/models/post.rb" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/3_2_release_notes.md" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/action_mailer_basics.md" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/active_record_querying.md" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/3_2_release_notes.md" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/action_mailer_basics.md" "/Users/ongaeshi/.milkode/packages/git/rails/guides/source/active_record_querying.md" "/Users/ongaeshi/.milkode/packages/git/rails/actionmailer/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/actionpack/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/actionview/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/actionview/RUNNING_UNIT_TESTS.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/activemodel/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/RUNNING_UNIT_TESTS.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/activesupport/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/railties/lib/rails/generators/rails/app/templates/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/railties/lib/rails/generators/rails/plugin/templates/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/railties/RDOC_MAIN.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/railties/README.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/RELEASING_RAILS.rdoc" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_many_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/base_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/calculations_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relation/merging_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relation_test.rb" "/Users/ongaeshi/.milkode/packages/git/rails/activerecord/test/cases/relations_test.rb"
å¿ç¨: ãã¡ã¤ã«ãããã£ã¼
å¼æ°ã«å ¨ã¦ããããããã¡ã¤ã«ã ããåºåããã¹ã¯ãªãããhelmãanythingã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ä½¿ãããã
require 'groonga' Groonga::Database.open("/Users/ongaeshi/.milkode/db/milkode.db") documents = Groonga["documents"] query = ARGV.map { |e| "restpath:@#{e}" }.join(" ") documents.select(query).each do |record| puts record.path end
$ ruby filematcher.rb slice hash /Users/ongaeshi/.milkode/packages/git/rails/activesupport/lib/active_support/core_ext/hash/slice.rb
ã¾ã¨ã
ãã¡ã¤ã«æ å ±ã«Rubyã¹ã¯ãªããçµç±ã§é«éã«ã¢ã¯ã»ã¹åºæ¥ãã®ã§å²ã¨å¿ç¨ç¯å²ã¯åºãã®ã§ã¯ãªããã¨èãã¦ãã¾ããé¢ç½ã使ãæ¹ãè¦ã¤ãããæ¯éããã°ãQiitaãªã©ã«æ¸ãã¦ãããã¨(ç§ã)åã³ã¾ãã
Honyomiãªã©ä»ã®Groongaãã¼ã¿ãã¼ã¹ã使ã£ã¦ããã¢ããªã±ã¼ã·ã§ã³ã§ãåããã¨ãåºæ¥ãã®ã§ã¯ãªããã¨æãã¾ãã