Class: Supernova::Solr::Server

Inherits:
Object
  • Object
show all
Includes:
FunctionalDelegator
Defined in:
lib/supernova/solr/server.rb

Direct Known Subclasses

Core

Constant Summary collapse

DEFAULT_PARAMS =
{
  :q => "*:*", :wt => "json"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FunctionalDelegator

included

Constructor Details

#initialize(url) ⇒ Server

Returns a new instance of Server.



9
10
11
# File 'lib/supernova/solr/server.rb', line 9

def initialize(url)
	@url = Supernova::Solr.remove_trailing_slash(url)
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/supernova/solr/server.rb', line 7

def url
  @url
end

Class Method Details

.body_from_docs(docs) ⇒ Object



34
35
36
# File 'lib/supernova/solr/server.rb', line 34

def body_from_docs(docs)
  docs.map { |doc| %({"add":) + hash_to_json({ :doc => doc }) + "}" }.join("\n")
end

.commit(core_url) ⇒ Object



50
51
52
# File 'lib/supernova/solr/server.rb', line 50

def commit(core_url)
  post_update(core_url, hash_to_json("commit" => {}))
end

.core_names(url) ⇒ Object



30
31
32
# File 'lib/supernova/solr/server.rb', line 30

def core_names(url)
  admin_action(url, "STATUS")["status"].keys
end

.delete_by_query(core_url, query, commit = false) ⇒ Object



58
59
60
# File 'lib/supernova/solr/server.rb', line 58

def delete_by_query(core_url, query, commit = false)
  post_update(core_url, hash_to_json("delete" => { "query" => query }), commit)
end

.hash_to_json(hash) ⇒ Object



22
23
24
# File 'lib/supernova/solr/server.rb', line 22

def hash_to_json(hash)
  JSON.dump(hash)
end

.index_doc(core_url, doc, commit = false) ⇒ Object



38
39
40
# File 'lib/supernova/solr/server.rb', line 38

def index_doc(core_url, doc, commit = false)
  index_docs(core_url, [doc], commit)
end

.index_docs(core_url, docs, commit = false) ⇒ Object



42
43
44
# File 'lib/supernova/solr/server.rb', line 42

def index_docs(core_url, docs, commit = false)
  post_update(core_url, body_from_docs(docs), commit)
end

.json_to_hash(json) ⇒ Object



26
27
28
# File 'lib/supernova/solr/server.rb', line 26

def json_to_hash(json)
  JSON.parse(json)
end

.optimize(core_url) ⇒ Object



54
55
56
# File 'lib/supernova/solr/server.rb', line 54

def optimize(core_url)
  post_update(core_url, hash_to_json("optimize" => {}))
end

.select(core_url, params = {}) ⇒ Object



46
47
48
# File 'lib/supernova/solr/server.rb', line 46

def select(core_url, params = {})
  get(core_url, "select", :params => DEFAULT_PARAMS.merge(params))
end

.truncate(core_url, commit = false) ⇒ Object



62
63
64
# File 'lib/supernova/solr/server.rb', line 62

def truncate(core_url, commit = false)
  delete_by_query(core_url, "*:*", commit)
end