Class: Milkode::SearchContents
- Inherits:
-
Object
- Object
- Milkode::SearchContents
- Defined in:
- lib/milkode/cdweb/lib/search_contents.rb
Defined Under Namespace
Classes: MatchRecord
Constant Summary collapse
- DISP_NUM =
1ページの表示数
20- LIMIT_NUM =
最大検索ファイル数
50- NTH =
表示範囲
3- COL_LIMIT =
1行の桁制限
200
Instance Attribute Summary collapse
-
#elapsed ⇒ Object
readonly
Returns the value of attribute elapsed.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
- #data_range ⇒ Object
- #html_contents ⇒ Object
- #html_pagination ⇒ Object
-
#initialize(path, params, query) ⇒ SearchContents
constructor
DISP_NUM = 1000 # 1ページの表示数 LIMIT_NUM = 1000 # 最大検索ファイル数 NTH = 3 # 表示範囲 COL_LIMIT = 200 # 1行の桁制限.
- #match_num ⇒ Object
- #next_offset ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(path, params, query) ⇒ SearchContents
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 29 def initialize(path, params, query) @path = path @params = params @q = query @page = params[:page].to_i || 0 @offset = params[:offset].to_i @line = params[:line].to_i @is_onematch = params[:onematch] @records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, path, @q.fpaths, @q.suffixs, @offset, LIMIT_NUM) grep_contents end |
Instance Attribute Details
#elapsed ⇒ Object (readonly)
Returns the value of attribute elapsed.
16 17 18 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 16 def elapsed @elapsed end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
17 18 19 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 17 def page @page end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
15 16 17 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 15 def total_records @total_records end |
Instance Method Details
#data_range ⇒ Object
49 50 51 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 49 def data_range @offset..(@offset + @end_index) end |
#html_contents ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 53 def html_contents match_groups = @match_records.reduce([]) do |g, m| if (g.empty?) g << [m] else prev = g[-1][-1] if (m.match_line.index - prev.match_line.index <= NTH * 2 && m.record.shortpath == prev.record.shortpath) g[-1] << m # グループの末尾に追加 g else g << [m] # 新規グループ end end # 近接マッチ無効 # g << [m] end match_groups.map{|g|result_match_record(g)}.join end |
#html_pagination ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 76 def html_pagination return "" if @q.empty? return "" if next_offset >= @total_records return <<EOF <div class='pagination'> #{pagination_link(next_offset, @next_line, "next >>")} </div> EOF end |
#match_num ⇒ Object
87 88 89 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 87 def match_num @match_records.size end |
#next_offset ⇒ Object
45 46 47 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 45 def next_offset @offset + @next_index end |
#query ⇒ Object
41 42 43 |
# File 'lib/milkode/cdweb/lib/search_contents.rb', line 41 def query @q.query_string end |