Class: Jekyll::LunrJsSearch::SearchEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_lunr_js_search/search_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, url, date, categories, tags, is_post, body, collection) ⇒ SearchEntry

Returns a new instance of SearchEntry.



32
33
34
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 32

def initialize(title, url, date, categories, tags, is_post, body, collection)
  @title, @url, @date, @categories, @tags, @is_post, @body, @collection = title, url, date, categories, tags, is_post, body, collection
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def body
  @body
end

#categoriesObject (readonly)

Returns the value of attribute categories.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def categories
  @categories
end

#collectionObject (readonly)

Returns the value of attribute collection.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def collection
  @collection
end

#dateObject (readonly)

Returns the value of attribute date.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def date
  @date
end

#is_postObject (readonly)

Returns the value of attribute is_post.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def is_post
  @is_post
end

#tagsObject (readonly)

Returns the value of attribute tags.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



30
31
32
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30

def url
  @url
end

Class Method Details

.create(site, renderer) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 6

def self.create(site, renderer)
  if site.is_a?(Jekyll::Page) or site.is_a?(Jekyll::Document)
    if defined?(site.date)
      date = site.date
    else
      date = nil
    end
    categories = site.data['categories']
    tags = site.data['tags']
    title, url = extract_title_and_url(site)
    is_post = site.is_a?(Jekyll::Document)
    body = renderer.render(site)

    SearchEntry.new(title, url, date, categories, tags, is_post, body, renderer)
  else
    raise 'Not supported'
  end
end

.extract_title_and_url(item) ⇒ Object



25
26
27
28
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 25

def self.extract_title_and_url(item)
  data = item.to_liquid
  [ data['title'], data['url'] ]
end

Instance Method Details

#strip_index_suffix_from_url!Object



36
37
38
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 36

def strip_index_suffix_from_url!
  @url.gsub!(/index\.html$/, '')
end

#strip_stopwords!(stopwords, min_length) ⇒ Object

remove anything that is in the stop words list from the text to be indexed



41
42
43
44
45
46
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 41

def strip_stopwords!(stopwords, min_length)
  @body = @body.split.delete_if() do |x|
    t = x.downcase.gsub(/[^a-z]/, '')
    t.length < min_length || stopwords.include?(t)
  end.join(' ')
end