Class: Jekyll::LunrJsSearch::SearchEntry
- Inherits:
-
Object
- Object
- Jekyll::LunrJsSearch::SearchEntry
- Defined in:
- lib/jekyll_lunr_js_search/search_entry.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#is_post ⇒ Object
readonly
Returns the value of attribute is_post.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title, url, date, categories, tags, is_post, body, collection) ⇒ SearchEntry
constructor
A new instance of SearchEntry.
- #strip_index_suffix_from_url! ⇒ Object
-
#strip_stopwords!(stopwords, min_length) ⇒ Object
remove anything that is in the stop words list from the text to be indexed.
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, , is_post, body, collection) @title, @url, @date, @categories, @tags, @is_post, @body, @collection = title, url, date, categories, , is_post, body, collection end |
Instance Attribute Details
#body ⇒ Object (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 |
#categories ⇒ Object (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 |
#collection ⇒ Object (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 |
#date ⇒ Object (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_post ⇒ Object (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 |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
30 31 32 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30 def @tags end |
#title ⇒ Object (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 |
#url ⇒ Object (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'] = 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, , 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 |