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

Refactor QueryMethods #97

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions lib/stretchy/querying.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Stretchy
module Querying
delegate :first, :first!, :last, :last!, :exists?, :has_field, :any?, :many?, to: :all
delegate :order, :limit, :size, :sort, :rewhere, :eager_load, :includes, :create_with, :none, :unscope, to: :all
delegate :or_filter, :fields, :source, :highlight, to: :all
delegate :neural_sparse, :neural, :hybrid, to: :all
delegate :first, :first!, :last, :last!, to: :all
delegate :exists?, :any?, :many?, :includes, to: :all
delegate :rewhere, :eager_load, :create_with, :none, :unscope, to: :all
delegate :routing, :search_options, to: :all

delegate *Stretchy::Relations::QueryMethods.registry, to: :all
delegate *Stretchy::Relations::AggregationMethods::AGGREGATION_METHODS, to: :all

delegate :skip_callbacks, :routing, :search_options, to: :all
delegate :must, :must_not, :should, :where_not, :where, :filter_query, :query_string, :regexp, to: :all

def fetch_results(es)
if es.count?
Expand All @@ -17,6 +17,5 @@ def fetch_results(es)
end
end


end
end
3 changes: 2 additions & 1 deletion lib/stretchy/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Stretchy
# It provides methods for querying and manipulating the documents.
class Relation


# These methods cannot be used with the `delete_all` method.
INVALID_METHODS_FOR_DELETE_ALL = [:limit, :offset]

Expand Down Expand Up @@ -146,7 +147,7 @@ def inspect
message.unshift entries.join(', ') unless entries.size.zero?
"#<#{self.class.name} #{message.join(', ')}>"
rescue StandardError => e
e
Stretchy.logger.error e.message
raise e
end
end
Expand Down
11 changes: 9 additions & 2 deletions lib/stretchy/relations/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def shoulds
@shoulds ||= compact_where(values[:should])
end

def ids
@ids ||= values[:ids]
end

def regexes
@regexes ||= values[:regexp]
end
Expand Down Expand Up @@ -105,7 +109,7 @@ def to_elastic
private

def missing_bool_query?
query.nil? && must_nots.nil? && shoulds.nil? && regexes.nil?
query.blank? && must_nots.nil? && shoulds.nil? && regexes.nil?
end

def missing_query_string?
Expand All @@ -121,12 +125,15 @@ def missing_neural?
end

def no_query?
missing_bool_query? && missing_query_string? && missing_query_filter? && missing_neural?
missing_bool_query? && missing_query_string? && missing_query_filter? && missing_neural? && ids.nil?
end

def build_query
return if no_query?
structure.query do
structure.ids do
structure.values ids.flatten.compact.uniq
end unless ids.nil?

structure.hybrid do
structure.queries do
Expand Down
Loading
Loading