Class: CodeStock::SearchContents

Inherits:
Object
  • Object
show all
Defined in:
lib/codestock/cdweb/lib/search_contents.rb

Defined Under Namespace

Classes: MatchRecord

Constant Summary collapse

DISP_NUM =

1ページの表示数

20
LIMIT_NUM =

最大検索ファイル数

50
NTH =

表示範囲

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, params, query) ⇒ SearchContents

Returns a new instance of SearchContents.



22
23
24
25
26
27
28
29
30
31
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 22

def initialize(path, params, query)
  @params = params
  @q = query
  @page = params[:page].to_i || 0
  @offset = params[:offset].to_i
  fpaths = @q.fpaths
  fpaths << path unless path == ""
  @records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, LIMIT_NUM)
  grep_contents
end

Instance Attribute Details

#elapsedObject (readonly)

Returns the value of attribute elapsed.



15
16
17
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 15

def elapsed
  @elapsed
end

#pageObject (readonly)

Returns the value of attribute page.



16
17
18
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 16

def page
  @page
end

#total_recordsObject (readonly)

Returns the value of attribute total_records.



14
15
16
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 14

def total_records
  @total_records
end

Instance Method Details

#data_rangeObject



41
42
43
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 41

def data_range
  @offset..(next_offset - 1)
end

#html_contentsObject



45
46
47
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 45

def html_contents
  @match_records.map {|match_record| result_match_record(match_record)}.join
end

#html_paginationObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 49

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

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

#next_offsetObject



37
38
39
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 37

def next_offset
  @offset + @next_index
end

#queryObject



33
34
35
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 33

def query
  @q.query_string
end