Object
# File lib/fastri/full_text_index.rb, line 47 def initialize(type, fulltext, sarray, options) options = DEFAULT_OPTIONS.merge(options) case type when :io @fulltext_IO = fulltext @sarray_IO = sarray when :filenames @fulltext_fname = fulltext @sarray_fname = sarray else raise "Unknown type" end @type = type @max_query_size = options[:max_query_size] check_magic end
# File lib/fastri/full_text_index.rb, line 136 def fetch_data(index, size, offset = 0) raise "Bad offset" unless offset <= 0 get_fulltext_IO do |fulltextIO| get_sarray_IO do |sarrayIO| base = index_to_offset(sarrayIO, index) actual_offset = offset newsize = size if base + offset < 0 # at the beginning excess = (base + offset).abs # remember offset is < 0 newsize = size - excess actual_offset = offset + excess end str = get_string(sarrayIO, fulltextIO, index, newsize, offset) from = (str.rindex("\00"", -actual_offset) || -1) + 1 to = (str.index("\00"", -actual_offset) || 0) - 1 str[from..to] end end end
# File lib/fastri/full_text_index.rb, line 63 def lookup(term) get_fulltext_IO do |fulltextIO| get_sarray_IO do |sarrayIO| case sarrayIO when StringIO num_suffixes = sarrayIO.string.size / 4 - 1 else num_suffixes = sarrayIO.stat.size / 4 - 1 end index, offset = binary_search(sarrayIO, fulltextIO, term, 0, num_suffixes) if offset fulltextIO.pos = offset path, metadata = find_metadata(fulltextIO) return Result.new(self, term, index, path, metadata) if path else nil end end end end
# File lib/fastri/full_text_index.rb, line 85 def next_match(result, term_or_regexp = "") case term_or_regexp when String; size = [result.query.size, term_or_regexp.size].max when Regexp; size = MAX_REGEXP_MATCH_SIZE end get_fulltext_IO do |fulltextIO| get_sarray_IO do |sarrayIO| idx = result.index loop do idx += 1 str = get_string(sarrayIO, fulltextIO, idx, size) upto = str.index("\00"") str = str[0, upto] if upto break unless str.index(result.query) == 0 if str[term_or_regexp] fulltextIO.pos = index_to_offset(sarrayIO, idx) path, metadata = find_metadata(fulltextIO) return Result.new(self, result.query, idx, path, metadata) if path end end end end end
# File lib/fastri/full_text_index.rb, line 109 def next_matches(result, term_or_regexp = "") case term_or_regexp when String; size = [result.query.size, term_or_regexp.size].max when Regexp; size = MAX_REGEXP_MATCH_SIZE end ret = [] get_fulltext_IO do |fulltextIO| get_sarray_IO do |sarrayIO| idx = result.index loop do idx += 1 str = get_string(sarrayIO, fulltextIO, idx, size) upto = str.index("\00"") str = str[0, upto] if upto break unless str.index(result.query) == 0 if str[term_or_regexp] fulltextIO.pos = index_to_offset(sarrayIO, idx) path, metadata = find_metadata(fulltextIO) ret << Result.new(self, result.query, idx, path, metadata) if path end end end end ret end
Generated with the Darkfish Rdoc Generator 2.