milkode 0.5.1 → 0.5.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -636,12 +636,12 @@ EOF
636
636
  end
637
637
 
638
638
  # データベースからも削除
639
- dir = File.expand_path(dir)
639
+ # dir = File.expand_path(dir)
640
640
 
641
641
  alert("rm_package", dir)
642
642
  @package_count += 1
643
643
 
644
- Database.instance.remove([File.basename(dir)]) do |record|
644
+ Database.instance.remove_fpath(dir) do |record|
645
645
  alert_info("rm_record", record.path)
646
646
  @file_count += 1
647
647
  end
@@ -59,6 +59,11 @@ EOF
59
59
  @contents.find {|v| v.same_name?(name)}
60
60
  end
61
61
 
62
+ # 指定キーワードにマッチする全てのパッケージを返す
63
+ def match_all(keyword)
64
+ @contents.find_all {|p| p.name.include? keyword }
65
+ end
66
+
62
67
  # ディレクトリ名が同じパッケージを検索
63
68
  def find_dir(directory)
64
69
  @contents.find {|v| v.directory == directory}
@@ -56,6 +56,10 @@ module Milkode
56
56
  @data.find_name(name)
57
57
  end
58
58
 
59
+ def match_all(keyword)
60
+ @data.match_all(keyword)
61
+ end
62
+
59
63
  def find_dir(dir)
60
64
  @data.find_dir(dir)
61
65
  end
@@ -52,7 +52,18 @@ module Milkode
52
52
  return table.records[0]
53
53
  end
54
54
 
55
- def search(patterns, packages, fpaths, suffixs, offset = 0, limit = -1)
55
+ def search(patterns, packages, current_path, fpaths, suffixs, offset = 0, limit = -1)
56
+ # パッケージ名から絶対パスに変換
57
+ unless packages.empty?
58
+ packages = convert_packages(packages)
59
+
60
+ # キーワードがパッケージ名にマッチしなければ検索しない
61
+ return [], 0 if packages.empty?
62
+ else
63
+ # パッケージ名未指定の時は現在位置もfpathsに含める
64
+ fpaths << current_path + "/" unless current_path == ""
65
+ end
66
+
56
67
  # @todo fpathを厳密に検索するには、検索結果からさらに先頭からのパスではないものを除外する
57
68
  records, total_records = searchMain(patterns, packages, fpaths, suffixs, offset, limit)
58
69
  end
@@ -131,14 +142,13 @@ module Milkode
131
142
  paths
132
143
  end
133
144
 
134
- # コンテンツの削除
135
- # @todo パッケージ名完全一致になっていないので直す
136
- def remove(packages)
145
+ # 指定したfpathにマッチするレコードを削除する
146
+ def remove_fpath(fpath)
137
147
  # データベースを開き直す
138
148
  reopen_patch
139
149
 
140
- # 削除したコンテンツをインデックスから削除
141
- records, total_records = search([], packages, [], [])
150
+ # 削除したいコンテンツを検索
151
+ records, total_records = searchMain([], [], [fpath], [], 0, -1)
142
152
 
143
153
  # 検索結果はHashのレコードなので、これを直接deleteしても駄目
144
154
  # 1. Record#record_idを使って主キー(Groonga#Arrayのレコード)を取り出し
@@ -222,23 +232,15 @@ module Milkode
222
232
  end
223
233
 
224
234
  # スコアとタイムスタンプでソート
225
- records = table.sort([{:key => "_score", :order => "descending"},
226
- {:key => "timestamp", :order => "descending"}],
227
- :offset => offset,
228
- :limit => limit)
229
-
230
- # ファイル名でソート
231
- # @todo 本当はこっちが望ましいが、パッケージ検索を正確にしないことには出来ない
232
- # records = table.sort([{:key => "shortpath", :order => "ascending"}],
235
+ # records = table.sort([{:key => "_score", :order => "descending"},
236
+ # {:key => "timestamp", :order => "descending"}],
233
237
  # :offset => offset,
234
238
  # :limit => limit)
235
-
236
- # パッケージの条件追加
237
- if (packages.size > 0)
238
- records.delete_if do |record|
239
- !packages.any?{|package| record.shortpath.split('/')[0] =~ /#{package}/ }
240
- end
241
- end
239
+
240
+ # ファイル名でソート
241
+ records = table.sort([{:key => "shortpath", :order => "ascending"}],
242
+ :offset => offset,
243
+ :limit => limit)
242
244
 
243
245
  # マッチ数
244
246
  total_records = table.size
@@ -281,5 +283,15 @@ module Milkode
281
283
  end
282
284
  private :suffix_expression
283
285
 
286
+ def convert_packages(packages)
287
+ packages.inject([]) {|r, p| r += expand_packages(p)}
288
+ end
289
+
290
+ def expand_packages(keyword)
291
+ @yaml.match_all(keyword).map{|p| p.directory}
292
+ end
293
+
294
+ # --- error ---
295
+ class NotFoundPackage < RuntimeError ; end
284
296
  end
285
297
  end
@@ -34,9 +34,7 @@ module Milkode
34
34
  @offset = params[:offset].to_i
35
35
  @line = params[:line].to_i
36
36
  @is_onematch = params[:onematch]
37
- fpaths = @q.fpaths
38
- fpaths << path + "/" unless path == ""
39
- @records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, LIMIT_NUM)
37
+ @records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, path, @q.fpaths, @q.suffixs, @offset, LIMIT_NUM)
40
38
  grep_contents
41
39
  end
42
40
 
@@ -23,13 +23,10 @@ module Milkode
23
23
 
24
24
  @offset = params[:offset].to_i
25
25
 
26
- fpaths = @q.fpaths
27
- fpaths << path + "/" unless path == ""
28
-
29
- if (fpaths.include?("*"))
26
+ if (@q.fpaths.include?("*"))
30
27
  @records, @total_records = Database.instance.selectAll(@offset, DISP_NUM)
31
28
  else
32
- @records, @total_records = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, DISP_NUM)
29
+ @records, @total_records = Database.instance.search(@q.keywords, @q.packages, path, @q.fpaths, @q.suffixs, @offset, DISP_NUM)
33
30
  end
34
31
  end
35
32
 
@@ -10,13 +10,13 @@
10
10
  %br
11
11
  %label
12
12
  = create_radio('all', params[:shead])
13
- 全体を検索
13
+ 全て
14
14
  %label
15
15
  = create_radio('package', params[:shead])
16
- = package_name(@path) + '以下'
16
+ パッケージ(おすすめ)
17
17
  %label
18
18
  = create_radio('directory', params[:shead])
19
- = current_name(@path) + '以下'
19
+ ディレクトリ
20
20
  %label
21
21
  = create_checkbox('onematch', params[:onematch])
22
22
  = '1ファイル1マッチ'
@@ -89,7 +89,7 @@ module Milkode
89
89
  end
90
90
 
91
91
  def larger_than_oneline(content)
92
- content.count("\n") > 1
92
+ content.count($/) > 1
93
93
  end
94
94
 
95
95
  def normalize_filename(str)
@@ -66,6 +66,8 @@ class TestCdstk < Test::Unit::TestCase
66
66
  # obj.update([], {})
67
67
  end
68
68
 
69
+ Database.instance.yaml_reload
70
+
69
71
  io.puts('--- remove ---')
70
72
  obj.remove(['findgrep'], {:force => true})
71
73
  obj.remove([], {:force => true})
@@ -66,8 +66,8 @@ module Milkode
66
66
 
67
67
  def t_remove
68
68
  db = Database.instance
69
- db.remove(['test'])
70
- db.remove(['lib'])
69
+ db.remove_fpath(File.expand_path '../../test')
70
+ db.remove_fpath(File.expand_path '../../lib')
71
71
  assert_equal 0, db.totalRecords
72
72
  end
73
73
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - ongaeshi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-15 00:00:00 +09:00
18
+ date: 2012-03-17 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency