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.



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

def initialize(index_cache)
  @cache = index_cache
end

Instance Method Details

#find_by_title(title) ⇒ Object



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

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

#stream_offset_for(title) ⇒ Object



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

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

#stream_offsetsObject



56
57
58
# File 'lib/wp2txt/corpus.rb', line 56

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