Class: SearchIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/coursegen/course/lib/search_data_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all_items) ⇒ SearchIndex

Returns a new instance of SearchIndex.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 3

def initialize all_items
  all_citems = all_items.map { |itm| Toc.instance.n2c(itm) }
  skiplist = Regexp.union([/\/search_index\/.*/, /\/bootstrap\/.*/, /\/config\/.*/, /\/tipuesearch\/.*/])
  @index = all_citems.select { |citem| citem.type == "page" && !citem.nitem.binary? && !citem.identifier.match(skiplist)}.map do
    |item|
#        puts "indexing: #{item.title}, match: #{item.identifier.match(skiplist) ? "true" : "false"}"
      nok_parse = Nokogiri::HTML(item.nitem.compiled_content).at('body')
      nok_parse_inner_text = nok_parse.nil? ? "" : nok_parse.inner_text
      { title:  clean_string(item.title),
        text:   clean_string(nok_parse_inner_text),
        tags:   "",
        loc:  item.nitem.rep_named(:default).path }
  end
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



2
3
4
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 2

def index
  @index
end

Instance Method Details

#clean_string(str) ⇒ Object



18
19
20
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 18

def clean_string str
  str.nil? ? "" : str.gsub(/(\s+|\"|\“|\”)/, " ")
end