Class: Relaton::FullTextSeatch
- Inherits:
-
Object
- Object
- Relaton::FullTextSeatch
- 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
-
#regex ⇒ Object
readonly
Regexp.
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#initialize(collection) ⇒ FullTextSeatch
constructor
A new instance of FullTextSeatch.
- #print_results ⇒ Object
- #search(text) ⇒ Array<Hash>
Constructor Details
#initialize(collection) ⇒ FullTextSeatch
Returns a new instance of FullTextSeatch.
16 17 18 |
# File 'lib/relaton/cli/full_text_search.rb', line 16 def initialize(collection) @collection = collection end |
Instance Attribute Details
#regex ⇒ Object (readonly)
Returns Regexp.
13 14 15 |
# File 'lib/relaton/cli/full_text_search.rb', line 13 def regex @regex end |
Instance Method Details
#any? ⇒ Boolean
39 40 41 |
# File 'lib/relaton/cli/full_text_search.rb', line 39 def any? @matches.any? end |
#print_results ⇒ Object
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>
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 |