Class: Madness::Search
Instance Method Summary
collapse
#disallowed_static?, #docroot, #find_static_file, #log, #theme
Constructor Details
#initialize(path = nil) ⇒ Search
9
10
11
|
# File 'lib/madness/search.rb', line 9
def initialize(path = nil)
@path = path || docroot
end
|
Instance Method Details
#index ⇒ Object
13
14
15
|
# File 'lib/madness/search.rb', line 13
def index
@index ||= index!
end
|
#search(query) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/madness/search.rb', line 17
def search(query)
query = query.downcase
words = Shellwords.split query
word_count = words.count
result = {}
return result if words.empty?
index.each do |file, content|
file = file.remove("#{@path}/").sub(/.md$/, '')
url = file_url file
label = file_label file
found = 0
words.each { |word| found += 1 if content.include? word }
next unless found == word_count
result[label] = url
end
result
end
|