Module: Gpr::Actions::Search
- Included in:
- Commands::Search
- Defined in:
- lib/gpr/actions/search.rb
Constant Summary collapse
- DB_PATH =
"#{::Gpr::APP_PATH}/.database"
Instance Method Summary collapse
Instance Method Details
#add_file(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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.(file), filename: File.basename(file), body: File.open(file).read, host: repo_info[:host], repository: repo_info[:repository] ) end end |
#git_ls_files(path) ⇒ Object
49 50 51 52 |
# File 'lib/gpr/actions/search.rb', line 49 def git_ls_files(path) Dir.chdir(path) `git ls-files`.split("\n") end |
#initialize_groonga ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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. = { 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 |