Class: Relaton::FullTextSeatch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ FullTextSeatch

Returns a new instance of FullTextSeatch.

Parameters:



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

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#regexObject (readonly)

Returns Regexp.

Returns:

  • Regexp



10
11
12
# File 'lib/relaton/cli/full_text_search.rb', line 10

def regex
  @regex
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/relaton/cli/full_text_search.rb', line 37

def any?
  @matches.any?
end


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>

Parameters:

  • text (String)

Returns:

  • (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