Class: Milkode::SearchFuzzyGotoLine

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/cdweb/lib/search_fuzzy_gotoline.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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SearchFuzzyGotoLine.



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

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.gotolines + @q.keywords)
  @gotoline = gotolines[0]

  # 検索
  fpaths = @q.fpaths + @gotoline[0]
  @records, @total_records = Database.instance.search([], @q.multi_match_keywords, @q.packages, path, fpaths, @q.suffixs, @q.fpath_or_packages, @offset, LIMIT_NUM)

  # 検索結果を表示
  grep_contents
end

Instance Attribute Details

#end_indexObject (readonly)

Returns the value of attribute end_index.



18
19
20
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 18

def end_index
  @end_index
end

#match_recordsObject (readonly)

Returns the value of attribute match_records.



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

def match_records
  @match_records
end

#next_indexObject (readonly)

Returns the value of attribute next_index.



17
18
19
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 17

def next_index
  @next_index
end

#total_recordsObject (readonly)

Returns the value of attribute total_records.



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

def total_records
  @total_records
end

Instance Method Details

#data_rangeObject



54
55
56
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 54

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

#directjump?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 84

def directjump?
  match_num == 1
end

#directjump_urlObject



88
89
90
91
92
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 88

def directjump_url
  path   = @homeurl + @match_records[0].record.shortpath
  lineno = "#n#{@gotoline[1]}"
  Mkurl.new(path, @params).inherit_query_shead + lineno
end

#html_contentsObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 58

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



69
70
71
72
73
74
75
76
77
78
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 69

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



80
81
82
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 80

def match_num
  @match_records.size
end

#next_offsetObject



50
51
52
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 50

def next_offset
  @offset + @next_index
end

#queryObject



46
47
48
# File 'lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb', line 46

def query
  @q.query_string
end