Class: SolrPanel::Client

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

Overview

Main client for the SolrPanel library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = 'http://localhost:8983/solr/', params = {}) ⇒ Client

, :f => “*,company_id”



34
35
36
37
38
# File 'lib/solrpanel/solrpanel.rb', line 34

def initialize(url = 'http://localhost:8983/solr/', params = {})
  @base_url = url
  @base_url = @base_url + '/' if (@base_url =~ /[^\/]+$/) 
  @default_query_parameters = params
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



29
30
31
# File 'lib/solrpanel/solrpanel.rb', line 29

def base_url
  @base_url
end

#default_query_parametersObject

Returns the value of attribute default_query_parameters.



30
31
32
# File 'lib/solrpanel/solrpanel.rb', line 30

def default_query_parameters
  @default_query_parameters
end

Instance Method Details

#commitObject



74
75
76
77
78
79
80
# File 'lib/solrpanel/solrpanel.rb', line 74

def commit()
  response = nil
  body = '<commit waitFlush="false" waitSearcher="false"/>'
  client = HTTPClient.new
  params = {'Content-Type' => 'text/xml'}
  response = client.request('POST', url('update'), nil, body, params)
end

#delete(id) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/solrpanel/solrpanel.rb', line 65

def delete(id)
  response = nil
  body = "<delete><id>#{id}</id></delete>"
  client = HTTPClient.new
  params = {'Content-Type' => 'text/xml'}
  response = client.request('POST', url('update'), nil, body, params)
end

#search(term, params = {}) ⇒ Object

Search for the term found in the



42
43
44
45
46
47
48
49
50
# File 'lib/solrpanel/solrpanel.rb', line 42

def search(term, params = {})
  client = HTTPClient.new
  parameters = { :q => term }.merge(params)
  puts @default_query_parameters.inspect
  parameters = parameters.merge(@default_query_parameters)
  response = client.post(url('select'), parameters)

  parse(response)
end

#update(path, id, params = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/solrpanel/solrpanel.rb', line 53

def update(path, id, params = {})
  response = nil
  File.open(path) do |file|
    body = { 'myfile' => file}
    update_params = {'literal.id' => id }
    update_params.merge!(params)
    client = HTTPClient.new
    response = client.request('POST', url('update/extract'), update_params, body)
  end
end