Class: Relaton::FullTextSeatch
- Inherits:
-
Object
- Object
- Relaton::FullTextSeatch
- Defined in:
- lib/relaton/cli/full_text_search.rb
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.
13 14 15 |
# File 'lib/relaton/cli/full_text_search.rb', line 13 def initialize(collection) @collection = collection end |
Instance Attribute Details
#regex ⇒ Object (readonly)
Returns Regexp.
10 11 12 |
# File 'lib/relaton/cli/full_text_search.rb', line 10 def regex @regex end |
Instance Method Details
#any? ⇒ Boolean
37 38 39 |
# File 'lib/relaton/cli/full_text_search.rb', line 37 def any? @matches.any? end |
#print_results ⇒ Object
29 30 31 32 33 34 |
# File 'lib/relaton/cli/full_text_search.rb', line 29 def print_results @matches.each do |docid, attrs| puts " Document ID: #{docid}" print_attrs attrs, 4 end end |
#search(text) ⇒ Array<Hash>
19 20 21 22 23 24 25 26 27 |
# File 'lib/relaton/cli/full_text_search.rb', line 19 def search(text) @regex = %{(.*?)(.{0,20})(#{text})(.{0,20})(.*)} @matches = @collection.items.reduce({}) do |m, item| # m + results(col, rgx) res = result item m[item.id] = res if res.any? m end end |