Class: ROM::Solr::DocumentsRelation

Inherits:
Relation
  • Object
show all
Defined in:
lib/rom/solr/relations/documents_relation.rb

Instance Method Summary collapse

Methods inherited from Relation

#log_params_list, #params, #response, #wt

Instance Method Details

#allObject



25
26
27
# File 'lib/rom/solr/relations/documents_relation.rb', line 25

def all
  q('*:*')
end

#by_unique_key(id) ⇒ Object



21
22
23
# File 'lib/rom/solr/relations/documents_relation.rb', line 21

def by_unique_key(id)
  q('%s:%s' % [ primary_key, id ])
end

#cache(enabled = true) ⇒ Object



87
88
89
# File 'lib/rom/solr/relations/documents_relation.rb', line 87

def cache(enabled = true)
  add_params(cache: Types::Bool[enabled])
end

#commit(value = true) ⇒ Object



140
141
142
# File 'lib/rom/solr/relations/documents_relation.rb', line 140

def commit(value = true)
  add_params(commit: Types::Bool[value])
end

#commit_within(millis) ⇒ Object



144
145
146
147
148
# File 'lib/rom/solr/relations/documents_relation.rb', line 144

def commit_within(millis)
  return self if millis.nil?

  add_params(commitWithin: Types::Coercible::Integer[millis])
end

#countObject



30
31
32
# File 'lib/rom/solr/relations/documents_relation.rb', line 30

def count
  num_found_exact ? num_found : super
end

#debug(setting) ⇒ Object



124
125
126
127
128
129
# File 'lib/rom/solr/relations/documents_relation.rb', line 124

def debug(setting)
  type = Types::Coercible::String
           .enum('query', 'timing', 'results', 'all', 'true')

  add_params(debug: type[setting])
end

#def_type(value) ⇒ Object



120
121
122
# File 'lib/rom/solr/relations/documents_relation.rb', line 120

def def_type(value)
  add_params(defType: Types::Coercible::String[value])
end

#delete(docs) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/rom/solr/relations/documents_relation.rb', line 59

def delete(docs)
  ids = Array.wrap(docs).map { |doc| doc.transform_keys(&:to_sym) }.map(&:id)

  with_options(
    base_path: 'update',
    content_type: 'application/json',
    request_data: JSON.dump(delete: ids)
  )
end

#each(&block) ⇒ Object



10
11
12
13
14
# File 'lib/rom/solr/relations/documents_relation.rb', line 10

def each(&block)
  return to_enum unless block_given?

  SelectCursor.new(dataset).each(&block)
end

#echo_params(setting) ⇒ Object



131
132
133
134
# File 'lib/rom/solr/relations/documents_relation.rb', line 131

def echo_params(setting)
  type = Types::Coercible::String.enum('explicit', 'all', 'none')
  add_params(echoParams: type[setting])
end

#explain_other(query) ⇒ Object



99
100
101
# File 'lib/rom/solr/relations/documents_relation.rb', line 99

def explain_other(query)
  add_params(explainOther: Types::String[query])
end

#expunge_deletes(value = true) ⇒ Object



154
155
156
# File 'lib/rom/solr/relations/documents_relation.rb', line 154

def expunge_deletes(value = true)
  add_params(expungeDeletes: Types::Bool[value])
end

#fl(*fields) ⇒ Object Also known as: fields



82
83
84
# File 'lib/rom/solr/relations/documents_relation.rb', line 82

def fl(*fields)
  add_params(fl: fields.join(','))
end

#fq(*filter) ⇒ Object Also known as: filter



77
78
79
# File 'lib/rom/solr/relations/documents_relation.rb', line 77

def fq(*filter)
  add_params(fq: filter)
end

#insert(docs) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/rom/solr/relations/documents_relation.rb', line 42

def insert(docs)
  data = Array.wrap(docs).map do |doc|
    doc.transform_keys!(&:to_sym)
    doc[:id] ||= UUID[]
  end

  update(data)
end

#min_exact_count(num) ⇒ Object



136
137
138
# File 'lib/rom/solr/relations/documents_relation.rb', line 136

def min_exact_count(num)
  add_params(minExactCount: Types::Coercible::Integer[num])
end

#num_foundObject



34
35
36
# File 'lib/rom/solr/relations/documents_relation.rb', line 34

def num_found
  response.dig(:response, :numFound)
end

#num_found_exactObject



38
39
40
# File 'lib/rom/solr/relations/documents_relation.rb', line 38

def num_found_exact
  response.dig(:response, :numFoundExact)
end

#omit_header(omit = true) ⇒ Object



103
104
105
# File 'lib/rom/solr/relations/documents_relation.rb', line 103

def omit_header(omit = true)
  add_params(omitHeader: Types::Bool[omit])
end

#overwrite(value = true) ⇒ Object



150
151
152
# File 'lib/rom/solr/relations/documents_relation.rb', line 150

def overwrite(value = true)
  add_params(overwrite: Types::Bool[value])
end

#primary_keyObject



17
18
19
# File 'lib/rom/solr/relations/documents_relation.rb', line 17

def primary_key
  :id
end

#q(query) ⇒ Object Also known as: query

Params



72
73
74
# File 'lib/rom/solr/relations/documents_relation.rb', line 72

def q(query)
  add_params(q: Types::String[query])
end

#rows(num) ⇒ Object Also known as: limit



115
116
117
# File 'lib/rom/solr/relations/documents_relation.rb', line 115

def rows(num)
  add_params(rows: Types::Coercible::Integer[num])
end

#segment_terminate_early(enabled = true) ⇒ Object



91
92
93
# File 'lib/rom/solr/relations/documents_relation.rb', line 91

def segment_terminate_early(enabled = true)
  add_params(segmentTerminateEarly: Types::Bool[enabled])
end

#sort(*criteria) ⇒ Object



111
112
113
# File 'lib/rom/solr/relations/documents_relation.rb', line 111

def sort(*criteria)
  add_params(sort: criteria.join(','))
end

#start(offset) ⇒ Object



107
108
109
# File 'lib/rom/solr/relations/documents_relation.rb', line 107

def start(offset)
  add_params(start: Types::Coercible::Integer[offset])
end

#time_allowed(millis) ⇒ Object



95
96
97
# File 'lib/rom/solr/relations/documents_relation.rb', line 95

def time_allowed(millis)
  add_params(timeAllowed: Types::Coercible::Integer[millis])
end

#update(docs) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/rom/solr/relations/documents_relation.rb', line 51

def update(docs)
  with_options(
    base_path: 'update/json/docs',
    content_type: 'application/json',
    request_data: JSON.dump(docs)
  )
end