Class: Nesta::Plugin::Search::Index
- Inherits:
-
Object
- Object
- Nesta::Plugin::Search::Index
- Defined in:
- lib/nesta-plugin-search/init.rb
Instance Attribute Summary collapse
-
#index_method ⇒ Object
Returns the value of attribute index_method.
Instance Method Summary collapse
- #index ⇒ Object
-
#initialize(imethod, timeout = false) ⇒ Index
constructor
Currently imethod is expected to be: - :find_all - :find_articles.
- #reindex ⇒ Object
Constructor Details
#initialize(imethod, timeout = false) ⇒ Index
Currently imethod is expected to be:
-
:find_all
-
:find_articles
Initializing with a timeout = false will cause index to not expire without a server restart.
51 52 53 54 55 56 57 |
# File 'lib/nesta-plugin-search/init.rb', line 51 def initialize(imethod, timeout=false) # 12 hours default @index_method = imethod.to_sym if timeout @timeout = timeout @expire_at = Time.now+timeout end end |
Instance Attribute Details
#index_method ⇒ Object
Returns the value of attribute index_method.
42 43 44 |
# File 'lib/nesta-plugin-search/init.rb', line 42 def index_method @index_method end |
Instance Method Details
#index ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nesta-plugin-search/init.rb', line 59 def index # index and return if index doesn't exist or is empty return @index = reindex unless @index && @index.size > 0 # return existing index if current index isn't expired or expired_at isn't set return @index if @expire_at && @expire_at > Time.now # if all else fails, index and return return @index = reindex end |
#reindex ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nesta-plugin-search/init.rb', line 70 def reindex @index = Ferret::Index::Index.new Nesta::Page.send(@index_method).each do |item| unless Nesta::Config.search_ignore_list.include?(item.abspath) @index << {:heading => item.heading, :href => item.abspath, :summary => item.summary, :body => item.body} end end @index end |