Class: ClWiki::MemoryIndexer
- Inherits:
-
Object
- Object
- ClWiki::MemoryIndexer
- Defined in:
- lib/cl_wiki/memory_indexer.rb
Constant Summary collapse
- WAIT =
true
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page_owner: PublicUser.new) ⇒ MemoryIndexer
constructor
A new instance of MemoryIndexer.
- #page_exists?(full_name) ⇒ Boolean
- #recent(top = -1,, text: '') ⇒ Object
- #reindex_page(page_name) ⇒ Object
- #search(text, titles_only: false) ⇒ Object
Constructor Details
#initialize(page_owner: PublicUser.new) ⇒ MemoryIndexer
Returns a new instance of MemoryIndexer.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cl_wiki/memory_indexer.rb', line 16 def initialize(page_owner: PublicUser.new) @page_owner = page_owner @wiki_conf = $wiki_conf @root_dir = @wiki_conf.wiki_path @index = ClIndex.new @recent = ClIndex.new @pages = ClIndex.new build end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/cl_wiki/memory_indexer.rb', line 8 def index @index end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
8 9 10 |
# File 'lib/cl_wiki/memory_indexer.rb', line 8 def pages @pages end |
Class Method Details
.instance(page_owner: PublicUser.new) ⇒ Object
12 13 14 |
# File 'lib/cl_wiki/memory_indexer.rb', line 12 def self.instance(page_owner: PublicUser.new) @instance ||= self.new(page_owner: page_owner) end |
Instance Method Details
#page_exists?(full_name) ⇒ Boolean
59 60 61 |
# File 'lib/cl_wiki/memory_indexer.rb', line 59 def page_exists?(full_name) @pages.term_exists?(full_name, WAIT) end |
#recent(top = -1,, text: '') ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cl_wiki/memory_indexer.rb', line 29 def recent(top = -1, text: '') pages_desc_mtime = @recent.do_read(WAIT) do hash = @recent.index hash.sort { |a, b| b[0] <=> a[0] } end.map { |_, page_names| page_names }.flatten if text && !text.empty? hit_page_names = search(text) pages_desc_mtime &= hit_page_names end pages_desc_mtime[0..top] end |
#reindex_page(page_name) ⇒ Object
63 64 65 66 |
# File 'lib/cl_wiki/memory_indexer.rb', line 63 def reindex_page(page_name) remove_page_from_index(page_name) index_page(page_name) end |
#search(text, titles_only: false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cl_wiki/memory_indexer.rb', line 43 def search(text, titles_only: false) terms = text.split(' ') all_hits = [] terms.each do |term| term_hits = [] @index.search(term, term_hits, WAIT) term_hits.flatten! all_hits = all_hits.empty? ? term_hits : all_hits & term_hits end all_hits.flatten! all_hits.uniq! all_hits.sort! all_hits.delete_if { |name| name !~ /#{text}/i } if titles_only all_hits end |