module Gpr::Actions::Search
Constants
- DB_PATH
Public Instance Methods
add_file(path)
click to toggle source
# File lib/gpr/actions/search.rb, line 34 def add_file(path) repo_info = parse_repository(path) git_ls_files(path).each do |file| next unless FileTest.file?(file) Groonga['Files'].add( File.expand_path(file), filename: File.basename(file), body: File.open(file).read, host: repo_info[:host], repository: repo_info[:repository] ) end end
git_ls_files(path)
click to toggle source
# File lib/gpr/actions/search.rb, line 49 def git_ls_files(path) Dir.chdir(path) `git ls-files`.split("\n") end
initialize_groonga()
click to toggle source
# File lib/gpr/actions/search.rb, line 10 def initialize_groonga if FileTest.exist?("#{DB_PATH}/gpr.db") Groonga::Database.open("#{DB_PATH}/gpr.db") else FileUtils.mkdir_p(DB_PATH) Groonga::Context.default_options = { encoding: :utf8 } Groonga::Database.create(path: "#{DB_PATH}/gpr.db") Groonga::Schema.create_table('Files', type: :patricia_trie) do |t| t.text('filename') t.text('body') t.text('host') t.text('repository') end Groonga::Schema.create_table( 'Terms', type: :patricia_trie, normalizer: :NormalizerAuto, default_tokenizer: 'TokenBigramSplitSymbolAlpha' ) do |t| t.index('Files.body') end end end