-
-
Save naoa/2be78db216c28856996d8e1a524a4a88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| table_create Books TABLE_HASH_KEY ShortText | |
| column_create Books authors COLUMN_VECTOR ShortText | |
| load --table Books | |
| [ | |
| {"_key": "Hello Groonga", "authors": ["Taro", "Hanako"]}, | |
| {"_key": "The first step for Groonga", "authors": ["Taro"]}, | |
| {"_key": "Mastering Groonga", "authors": ["Hanako"]} | |
| ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ostruct' | |
| require 'json' | |
| cmd = "groonga /tmp/db" | |
| query = "select Books --drilldown authors --command_version 3" | |
| #query = "select Books --drilldowns[authors] authors --command_version 3" | |
| ret = `#{cmd} #{query}` | |
| results = JSON.parse ret | |
| elapsed_time = results["header"]["elapsed_time"] | |
| n_hits = results["body"]["n_hits"] | |
| columns = results["body"]["columns"].map {|c| c["name"] } | |
| docs = results["body"]["records"].map do |record| | |
| doc = {} | |
| record.each_with_index {|value, t| doc[columns[t]] = value } | |
| OpenStruct.new(doc) | |
| end | |
| puts n_hits | |
| docs.each do |doc| | |
| puts "#{doc._key}: #{doc.authors}" | |
| end | |
| #n_hits = results["body"]["drilldowns"]["authors"]["n_hits"] | |
| #columns = results["body"]["drilldowns"]["authors"]["columns"].map {|c| c["name"] } | |
| #docs = results["body"]["drilldowns"]["authors"]["records"].map do |record| | |
| # doc = {} | |
| # record.each_with_index {|value, t| doc[columns[t]] = value } | |
| # OpenStruct.new(doc) | |
| #end | |
| #puts n_hits | |
| #docs.each do |doc| | |
| # puts "#{doc._key}: #{doc._nsubrecs}" | |
| #end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment