lib/search_flip/criteria.rb in search_flip-2.1.0 vs lib/search_flip/criteria.rb in search_flip-2.2.0

- old
+ new

@@ -20,11 +20,11 @@ extend Forwardable attr_accessor :target, :profile_value, :source_value, :sort_values, :highlight_values, :suggest_values, :offset_value, :limit_value, :includes_values, :eager_load_values, :preload_values, :failsafe_value, :scroll_args, :custom_value, :terminate_after_value, :timeout_value, :preference_value, - :search_type_value, :routing_value + :search_type_value, :routing_value, :track_total_hits_value # Creates a new criteria while merging the attributes (constraints, # settings, etc) of the current criteria with the attributes of another one # passed as argument. For multi-value contstraints the resulting criteria # will include constraints of both criterias. For single-value constraints, @@ -49,10 +49,11 @@ criteria.scroll_args = other.scroll_args if other.scroll_args criteria.source_value = other.source_value if other.source_value criteria.preference_value = other.preference_value if other.preference_value criteria.search_type_value = other.search_type_value if other.search_type_value criteria.routing_value = other.routing_value if other.routing_value + criteria.track_total_hits_value = other.track_total_hits_value unless other.track_total_hits_value.nil? criteria.sort_values = (criteria.sort_values || []) + other.sort_values if other.sort_values criteria.includes_values = (criteria.includes_values || []) + other.includes_values if other.includes_values criteria.preload_values = (criteria.preload_values || []) + other.preload_values if other.preload_values criteria.eager_load_values = (criteria.eager_load_values || []) + other.eager_load_values if other.eager_load_values @@ -72,10 +73,27 @@ criteria.custom_value = (criteria.custom_value || {}).merge(other.custom_value) if other.custom_value criteria.aggregation_values = (criteria.aggregation_values || {}).merge(other.aggregation_values) if other.aggregation_values end end + # Specifies if or how many hits should be counted/tracked. Check out the + # elasticsearch docs for futher details. + # + # @example + # CommentIndex.track_total_hits(true) + # CommentIndex.track_total_hits(10_000) + # + # @param value The value for track_total_hits + # + # @return [SearchFlip::Criteria] A newly created extended criteria + + def track_total_hits(value) + fresh.tap do |criteria| + criteria.track_total_hits_value = value + end + end + # Specifies a preference value for the request. Check out the elasticsearch # docs for further details. # # @example # CommentIndex.preference("_primary") @@ -165,10 +183,12 @@ # @param scopes [Symbol] All scopes that you want to remove # # @return [SearchFlip::Criteria] A newly created extended criteria def unscope(*scopes) + warn "[DEPRECATION] unscope is deprecated" + unknown = scopes - [:search, :post_search, :sort, :highlight, :suggest, :custom, :aggregate] raise(ArgumentError, "Can't unscope #{unknown.join(", ")}") if unknown.size > 0 scopes = scopes.to_set @@ -258,9 +278,10 @@ end end res.update from: offset_value_with_default, size: limit_value_with_default + res[:track_total_hits] = track_total_hits_value unless track_total_hits_value.nil? res[:timeout] = timeout_value if timeout_value res[:terminate_after] = terminate_after_value if terminate_after_value res[:highlight] = highlight_values if highlight_values res[:suggest] = suggest_values if suggest_values res[:sort] = sort_values if sort_values