Class: Wp2txt::Corpus::LazyTitleIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2txt/corpus.rb

Overview

Duck-typed replacement for MultistreamIndex that resolves titles through the IndexCache SQLite file on demand, avoiding loading millions of index entries into memory (important for long-lived server processes).

Instance Method Summary collapse

Constructor Details

#initialize(index_cache) ⇒ LazyTitleIndex

Returns a new instance of LazyTitleIndex.



41
42
43
# File 'lib/wp2txt/corpus.rb', line 41

def initialize(index_cache)
  @cache = index_cache
end

Instance Method Details

#find_by_title(title) ⇒ Object



45
46
47
# File 'lib/wp2txt/corpus.rb', line 45

def find_by_title(title)
  @cache.find_by_titles([title])[title]
end

#stream_offset_for(title) ⇒ Object



49
50
51
# File 'lib/wp2txt/corpus.rb', line 49

def stream_offset_for(title)
  find_by_title(title)&.fetch(:offset, nil)
end

#stream_offsetsObject



53
54
55
# File 'lib/wp2txt/corpus.rb', line 53

def stream_offsets
  @stream_offsets ||= @cache.stream_offsets
end