Class: Milkode::SearchGotoLine

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/cdweb/lib/search_gotoline.rb

Defined Under Namespace

Classes: MatchRecord

Constant Summary collapse

DISP_NUM =

1ページの表示数

20
LIMIT_NUM =

最大検索ファイル数

50
NTH =

表示範囲

3
COL_LIMIT =

1行の桁制限

200
MATH_FILE_DISP =

マッチファイルの最大表示数

3
MATH_FILE_LIMIT =

マッチファイルの検索リミット数

MATH_FILE_DISP + 1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, params, query, suburl) ⇒ SearchGotoLine

Returns a new instance of SearchGotoLine.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 26

def initialize(path, params, query, suburl)
  @path    = path
  @params  = params
  @q       = query
  @page    = params[:page].to_i || 0
  @offset  = params[:offset].to_i
  @suburl  = suburl
  @homeurl = @suburl + "/home/"

  # 検索クエリを解析
  @gotolines = Util.parse_gotoline(@q.keywords)

  # レコードをピックアップ
  @records = []
  @gotolines.each do |v|
    @records << Database.instance.record(v[0][0][1..-1])
  end
  @total_records = @records.size

  # 検索結果を表示
  grep_contents
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



16
17
18
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 16

def page
  @page
end

#total_recordsObject (readonly)

Returns the value of attribute total_records.



15
16
17
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 15

def total_records
  @total_records
end

Instance Method Details

#data_rangeObject



57
58
59
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 57

def data_range
  @offset..(@offset + @end_index)
end

#html_contentsObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 61

def html_contents
  match_groups = @match_records.reduce([]) do |g, m|
    # 近接マッチ無効
    g << [m]
  end
  
  <<EOF
#{match_groups.map{|g|result_match_record(g)}.join}
EOF
end

#html_paginationObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 72

def html_pagination
  return "" if @q.empty?
  return "" if next_offset >= @total_records

  return <<EOF
<div class='pagination pagination-centered'>
#{pagination_link(next_offset, @next_line, "next >>")}
</div>
EOF
end

#match_numObject



83
84
85
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 83

def match_num
  @match_records.size
end

#next_offsetObject



53
54
55
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 53

def next_offset
  @offset + @next_index
end

#queryObject



49
50
51
# File 'lib/milkode/cdweb/lib/search_gotoline.rb', line 49

def query
  @q.query_string
end