class Milkode::SearchFiles
Constants
- DISP_NUM
Attributes
total_records[R]
Public Class Methods
new(path, params, query, suburl)
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 19 def initialize(path, params, query, suburl) @path = path @params = params @q = query @suburl = suburl @homeurl = @suburl + "/home/" @offset = params[:offset].to_i if (@q.fpaths.include?("*")) @records, @total_records = Database.instance.selectAll(path, @offset, DISP_NUM) else @records, @total_records = Database.instance.search(@q.keywords, @q.multi_match_keywords, @q.packages, path, @q.fpaths, @q.suffixs, @q.fpath_or_packages, @offset, DISP_NUM) end end
Public Instance Methods
data_range()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 43 def data_range @offset..(next_offset - 1) end
html_contents()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 47 def html_contents @records.map {|record| result_record(DocumentRecord.new(record))}.join end
html_pagination()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 51 def html_pagination return "" if @q.empty? return "" if @total_records < DISP_NUM return <<EOF <div class='pagination pagination-centered'> #{pagination_link(next_offset, "next >>")} </div> EOF end
match_num()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 62 def match_num @records.size end
next_offset()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 39 def next_offset @offset + @records.size end
query()
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 35 def query @q.query_string end
Private Instance Methods
pagination_link(offset, label)
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 68 def pagination_link(offset, label) tmpp = @params tmpp[:offset] = offset.to_s href = Mkurl.new("", tmpp).inherit_query_shead_offset pagination_span("<a href='#{href}' rel='next'>#{label}</a>") end
pagination_span(content)
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 75 def pagination_span(content) "<ul><li>#{content}</li></ul>\n" end
record_link(record)
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 88 def record_link(record) Mkurl.new(record.shortpath, @params).inherit_query_shead end
result_record(record)
click to toggle source
# File lib/milkode/cdweb/lib/search_files.rb, line 79 def result_record(record) filename = Util.relative_path(record.shortpath, @path).to_s filename = Util.highlight_keywords(filename, @q.fpaths + @q.fpath_or_packages, 'highlight-filename') <<EOS <dt class='result-file'>#{file_or_dirimg(true, @suburl)}<a href='#{@homeurl + record_link(record)}'>#{filename}</a></dt> EOS end