Class: DxTitleSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/dxtitle_search.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, sources: nil, level: 1, debug: false) ⇒ DxTitleSearch

Returns a new instance of DxTitleSearch.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dxtitle_search.rb', line 10

def initialize(obj=nil, sources: nil, level: 1, debug: false)

  @debug = debug
  @indexer = Indexer101.new debug: debug

  s = if sources then
  
    dx = Dynarex.new(sources)      
    puts 'before scan_dxindex' if @debug
    a = dx.all.map(&:uri)
    puts 'a: ' + a.inspect if @debug
    @indexer.scan_dxindex a, level: level
  
  elsif obj and obj.lines.length < 2 

    @indexer.scan_dxindex  obj, level: level
      
  end

  #jr230620 @indexer.build

end

Instance Method Details

#search(keywords, minchars: 3) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dxtitle_search.rb', line 33

def search(keywords, minchars: 3)    

  a2 = @indexer.search keywords.split(/[\s:"!\?\(\)£]+(?=[\w#_'-]+)/), \
      minchars: minchars
  # format each result as a Hash object
  a3 = a2.map do |date, title, url|

    {title: title, url: url, date: date}

  end

  puts 'a3: ' + a3.inspect if @debug
  
  def a3.to_dx()
    Dynarex.new('results/result(title, url, date)').import(self)
  end

  return a3

end

#tag_search(keywords) ⇒ Object



54
55
56
57
# File 'lib/dxtitle_search.rb', line 54

def tag_search(keywords)    
  r = @indexer.lookup *keywords.split(/[\W]+(?=[\w]+)/).map {|x| "#" + x}
  r.map {|x| x.to_s[1..-1]}
end