Skip to content

Commit

Permalink
fix typo in indexOptimize call
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 25, 2024
1 parent e461c2d commit 51fbfe4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.8)
rack (2.2.8.1)
rack-accept (0.4.5)
rack (>= 0.4)
rack-post-body-to-params (0.1.8)
Expand Down
2 changes: 1 addition & 1 deletion lib/goo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def self.search_connections
end

def self.init_search_connection(collection_name, search_backend = :main, block = nil, force: false)
return if @@search_connection[collection_name] && !force
return @@search_connection[collection_name] if @@search_connection[collection_name] && !force

@@search_connection[collection_name] = SOLR::SolrConnector.new(search_conf(search_backend), collection_name)
if block
Expand Down
51 changes: 25 additions & 26 deletions lib/goo/search/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ def index(connection_name = nil, to_set = nil)
self.class.search_client(connection_name).index_document(document)
end


def index_update(attributes_to_update, connection_name = nil, to_set = nil)
raise ArgumentError, "ID must be set to be able to index" if @id.nil?
raise ArgumentError, "Field names to be updated in index must be provided" if attributes_to_update.blank?

Check warning on line 25 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L25

Added line #L25 was not covered by tests

old_doc = self.class.search("id:\"#{index_id}\"").dig("response","docs")&.first
old_doc = self.class.search("id:\"#{index_id}\"").dig("response", "docs")&.first

Check warning on line 27 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L27

Added line #L27 was not covered by tests

raise ArgumentError, "ID must be set to be able to index" if old_doc.blank?

Check warning on line 29 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L29

Added line #L29 was not covered by tests

doc = indexable_object(to_set)

doc.each do |key, val|
next unless attributes_to_update.any?{ |attr| key.to_s.eql?(attr.to_s) || key.to_s.include?("#{attr}_")}
next unless attributes_to_update.any? { |attr| key.to_s.eql?(attr.to_s) || key.to_s.include?("#{attr}_") }
old_doc[key] = val

Check warning on line 35 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L33-L35

Added lines #L33 - L35 were not covered by tests
end

connection_name ||= self.class.search_collection_name
unindex(connection_name)

Check warning on line 39 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L38-L39

Added lines #L38 - L39 were not covered by tests

old_doc.reject!{|k,v| k.to_s.end_with?('_sort') || k.to_s.end_with?('_sorts')}
old_doc.reject! { |k, v| k.to_s.end_with?('_sort') || k.to_s.end_with?('_sorts') }
old_doc.delete("_version_")
self.class.search_client(connection_name).index_document(old_doc)

Check warning on line 43 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L41-L43

Added lines #L41 - L43 were not covered by tests
end
Expand Down Expand Up @@ -67,32 +66,32 @@ def embedded_doc
def indexable_object(to_set = nil)
begin
document = index_doc(to_set)
rescue
document = self.to_hash.reject { |k, _| !self.class.indexable?(k) }
document.transform_values! do |v|
is_array = v.is_a?(Array)
v = Array(v).map do |x|
if x.is_a?(Goo::Base::Resource)
x.embedded_doc rescue x.id.to_s
rescue NoMethodError
document = self.to_hash.reject { |k, _| !self.class.indexable?(k) }
document.transform_values! do |v|
is_array = v.is_a?(Array)
v = Array(v).map do |x|
if x.is_a?(Goo::Base::Resource)
x.embedded_doc rescue x.id.to_s
else
if x.is_a?(RDF::URI)
x.to_s

Check warning on line 78 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L78

Added line #L78 was not covered by tests
else
if x.is_a?(RDF::URI)
x.to_s
else
x.respond_to?(:object) ? x.object : x
end
x.respond_to?(:object) ? x.object : x
end
end
is_array ? v : v.first
end
is_array ? v : v.first
end
end

document = document.reduce({}) do |h, (k, v)|
if v.is_a?(Hash)
v.each { |k2, v2| h["#{k}_#{k2}".to_sym] = v2 }
else
h[k] = v
end
h
end
document = document.reduce({}) do |h, (k, v)|
if v.is_a?(Hash)
v.each { |k2, v2| h["#{k}_#{k2}".to_sym] = v2 }

Check warning on line 90 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L90

Added line #L90 was not covered by tests
else
h[k] = v
end
h
end

model_name = self.class.model_name.to_s.downcase
Expand Down Expand Up @@ -177,7 +176,7 @@ def indexCommit(attrs = nil, connection_name = search_collection_name)
end

def indexOptimize(attrs = nil, connection_name = search_collection_name)
search_client(connection_name).optimize(attrs)
search_client(connection_name).index_optimize(attrs)

Check warning on line 179 in lib/goo/search/search.rb

View check run for this annotation

Codecov / codecov/patch

lib/goo/search/search.rb#L179

Added line #L179 was not covered by tests
end

# WARNING: this deletes ALL data from the index
Expand Down

0 comments on commit 51fbfe4

Please sign in to comment.