Class: Relaton::FullTextSeatch

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/cli/full_text_search.rb

Constant Summary collapse

INTERNAL_IVARS =

Instance variables added by lutaml-model that form back-references (cycles) when a model is serialized. Skipping them keeps recursive traversal of a bibitem’s object graph finite.

%i[
  @using_default @lutaml_register @lutaml_parent @lutaml_root @register_records
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ FullTextSeatch

Returns a new instance of FullTextSeatch.

Parameters:



16
17
18
# File 'lib/relaton/cli/full_text_search.rb', line 16

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#regexObject (readonly)

Returns Regexp.

Returns:

  • Regexp



13
14
15
# File 'lib/relaton/cli/full_text_search.rb', line 13

def regex
  @regex
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/relaton/cli/full_text_search.rb', line 39

def any?
  @matches.any?
end


31
32
33
34
35
36
# File 'lib/relaton/cli/full_text_search.rb', line 31

def print_results
  @matches.each do |docid, attrs|
    puts "  Document ID: #{docid}"
    print_attrs attrs, 4
  end
end

#search(text) ⇒ Array<Hash>

Parameters:

  • text (String)

Returns:

  • (Array<Hash>)


22
23
24
25
26
27
28
29
# File 'lib/relaton/cli/full_text_search.rb', line 22

def search(text)
  @regex = %{(.*?)(.{0,20})(#{text})(.{0,20})(.*)}
  @matches = @collection.items.reduce({}) do |m, item|
    res = result item, Set.new
    m[item.id] = res if res.any?
    m
  end
end