Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete non indexable documents #5

Merged
merged 1 commit into from
May 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/chewy/type/adapter/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def import_objects(collection, options)
!collection.empty? &&
collection.all? { |item| item.is_a?(::Mongoid::Document) && item.__selected_fields.nil? }

if direct_import && @options[:searchable_proc]
collection = collection.select do |c|
@options[:searchable_proc].call(c)
end
end

collection_ids = identify(collection)
hash = Hash[collection_ids.map(&:to_s).zip(collection)]

Expand All @@ -57,6 +51,11 @@ def import_objects(collection, options)

batch = batch.to_a

# If it's not searchable/indexable, we should delete it.
if direct_import && @options[:searchable_proc]
batch = batch.select { |object| @options[:searchable_proc].call(object) }
end

if batch.empty?
true
else
Expand Down