findrr 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS.md +16 -0
- data/lib/findrr/command.rb +21 -2
- data/lib/findrr/database.rb +25 -17
- data/lib/findrr/version.rb +1 -1
- data/test/test-database.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b43b8b92b94614de19cfb1c1285e7c1aeab611fb
|
4
|
+
data.tar.gz: 989e319e2cfc2aabbac32c511fe73f58dde0501b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7022195f168af37305ef489d0fa8a0ccba04de6bd0dd21f3f8cf52f9758ad3b53b5c6168e7ce3dc124e7a6b1400bc1f853060ab6031e0f81505b7967221d93b4
|
7
|
+
data.tar.gz: 1d60e28709ef47dba08d835fb0c9f461aaf05cbecac930f70a8114cb5bf32a4de8038b8bcb34798f5c4a744d80570917bd723733bca3a26c838a75bccdd05ced
|
data/NEWS.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# NEWS
|
2
|
+
|
3
|
+
## 0.0.2: 2013-12-13
|
4
|
+
|
5
|
+
Improve the table shcema!
|
6
|
+
|
7
|
+
### Changes
|
8
|
+
|
9
|
+
* Improvements
|
10
|
+
* Use PatriciaTrie for type of "Files" table.
|
11
|
+
* Added "mtime" column to "Files" table.
|
12
|
+
* Added "destroy" command as delete the database.
|
13
|
+
|
14
|
+
## 0.0.1: 2013-12-09
|
15
|
+
|
16
|
+
Initial release!
|
data/lib/findrr/command.rb
CHANGED
@@ -5,12 +5,31 @@ module Findrr
|
|
5
5
|
class Command < Thor
|
6
6
|
desc "collect PATH", "Collect filenames (take a few minutes)"
|
7
7
|
def collect(path)
|
8
|
-
|
8
|
+
begin
|
9
|
+
Database.new.collect(path)
|
10
|
+
rescue => e
|
11
|
+
$stderr.puts <<-END_OF_MESSAGE
|
12
|
+
Error: #{e.message}
|
13
|
+
Hint: table schema might be changed. Please try `findrr destroy` command.
|
14
|
+
END_OF_MESSAGE
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
desc "search PART_OF_FILENAME", "Search for filenames in the collection"
|
12
19
|
def search(part_of_filename)
|
13
|
-
|
20
|
+
begin
|
21
|
+
Database.new.search(part_of_filename)
|
22
|
+
rescue => e
|
23
|
+
$stderr.puts <<-END_OF_MESSAGE
|
24
|
+
Error: #{e.message}
|
25
|
+
Hint: database probably isn't created. Please try `findrr collect` command.
|
26
|
+
END_OF_MESSAGE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "destroy", "Delete the database and the collection"
|
31
|
+
def destroy
|
32
|
+
Database.new.destroy
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
data/lib/findrr/database.rb
CHANGED
@@ -10,13 +10,15 @@ module Findrr
|
|
10
10
|
Groonga::Context.default_options = {:encoding => :utf8}
|
11
11
|
end
|
12
12
|
|
13
|
-
def collect(
|
13
|
+
def collect(target)
|
14
14
|
create_database_dir
|
15
15
|
create_database
|
16
16
|
Groonga::Database.open(database_path) do
|
17
|
+
Groonga["Registers"].add(target)
|
17
18
|
files = Groonga["Files"]
|
18
|
-
Find.find(File.expand_path(
|
19
|
-
files.add(path, :basename => File.basename(path)
|
19
|
+
Find.find(File.expand_path(target)) do |path|
|
20
|
+
files.add(path, :basename => File.basename(path),
|
21
|
+
:mtime => File.mtime(path))
|
20
22
|
end
|
21
23
|
files.size
|
22
24
|
end
|
@@ -35,6 +37,10 @@ module Findrr
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
40
|
+
def destroy
|
41
|
+
FileUtils.rm_rf(database_dir)
|
42
|
+
end
|
43
|
+
|
38
44
|
private
|
39
45
|
def default_base_dir
|
40
46
|
File.join(File.expand_path("~"), ".findrr")
|
@@ -49,25 +55,27 @@ module Findrr
|
|
49
55
|
end
|
50
56
|
|
51
57
|
def create_database_dir
|
52
|
-
|
53
|
-
|
54
|
-
end
|
58
|
+
return if File.exist?(database_dir)
|
59
|
+
FileUtils.mkdir_p(database_dir)
|
55
60
|
end
|
56
61
|
|
57
62
|
def create_database
|
58
|
-
|
59
|
-
Groonga::Database.create(:path => database_path)
|
63
|
+
return if File.exist?(database_path)
|
60
64
|
|
61
|
-
|
62
|
-
table.text("basename")
|
63
|
-
end
|
65
|
+
Groonga::Database.create(:path => database_path)
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
Groonga::Schema.create_table("Registers", :type => :hash)
|
68
|
+
|
69
|
+
Groonga::Schema.create_table("Files", :type => :patricia_trie) do |table|
|
70
|
+
table.text("basename")
|
71
|
+
table.time("mtime")
|
72
|
+
end
|
73
|
+
|
74
|
+
Groonga::Schema.create_table("Terms",
|
75
|
+
:type => :patricia_trie,
|
76
|
+
:normalizer => :NormalizerAuto,
|
77
|
+
:default_tokenizer => "TokenBigram") do |table|
|
78
|
+
table.index("Files.basename")
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
data/lib/findrr/version.rb
CHANGED
data/test/test-database.rb
CHANGED
@@ -17,4 +17,11 @@ class DatabaseTest < Test::Unit::TestCase
|
|
17
17
|
assert_true(0 < @database.collect(File.dirname(__FILE__)))
|
18
18
|
assert_true(0 < @database.search("test"))
|
19
19
|
end
|
20
|
+
|
21
|
+
def test_destroy
|
22
|
+
@database.collect(File.dirname(__FILE__))
|
23
|
+
assert_true(File.exist?(@tmp_db_dir))
|
24
|
+
@database.destroy
|
25
|
+
assert_false(File.exist?(@tmp_db_dir))
|
26
|
+
end
|
20
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: findrr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masafumi Yokoyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rroonga
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".gitignore"
|
120
120
|
- ".travis.yml"
|
121
121
|
- Gemfile
|
122
|
+
- NEWS.md
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
125
|
- bin/findrr
|