lib/ddr/index/query_builder.rb in ddr-models-2.4.12 vs lib/ddr/index/query_builder.rb in ddr-models-2.4.13

- old
+ new

@@ -26,13 +26,10 @@ # desc [field], ... # Adds descending orderings by the fields specified. # # See also: asc, order_by # - # id [doc_id] - # For selecting a single document by ID. - # # filter [filter1], ... # Adds filters to the query. # # Aliased as: filters # @@ -46,10 +43,16 @@ # Aliased as: fields # # fields [field], ... # Alias for: field # + # id [doc_id] + # For selecting a single document by ID. + # + # join [from: {field1}, to: {field2}, where: {condition}] + # Adds a Solr join clause (see https://wiki.apache.org/solr/Join) + # # limit [int] # Limits the number of documents returned by the query. # # Aliased as: rows # @@ -72,10 +75,15 @@ # Sets a query clause for the `q` parameter. # # raw [clause1], ... # Adds a filter of "raw" query clauses (i.e., pre-constructed). # + # regexp [field], [regexp] + # Adds a filter selecting documents where the field has a value + # matching the regular expression. + # Slashes (/) in the regexp will be escaped as required by Solr. + # # rows [int] # Alias for: limit # # sort [{field => order, ...}] # Alias for: order_by @@ -89,28 +97,16 @@ # If a hash value is an array, that query clause will select documents # where the field matches any array entry. # class QueryBuilder - # Builds a Query object - # @yield [builder] a new QueryBuilder instance. - # @return [Query] - def self.build - Deprecation.warn(self, - "`Ddr::Index::QueryBuilder.build` is deprecated and will be removed in ddr-models 3.0." \ - " Use `Ddr::Index::QueryBuilder.new` instead.") - builder = new - yield builder - builder.query - end - attr_reader :query - def initialize(query = nil, &block) - @query = query || Query.new + def initialize(*args, &block) + @query = args.first.is_a?(Query) ? args.shift : Query.new if block_given? - instance_eval &block + instance_exec(*args, &block) end end # @param pid [String] # @return [QueryBuilder] @@ -144,14 +140,9 @@ alias_method :rows, :limit # @param orderings [Hash<Field, String>] # @return [QueryBuilder] self def order_by(*orderings) - unless orderings.first.is_a? Hash - Deprecation.warn(QueryBuilder, "`order_by` will require a hash of orderings in ddr-models 3.0.") - field, order = orderings - return order_by(field => order) - end query.sort += orderings.first.map { |field, order| SortOrder.new(field: field, order: order) } self end alias_method :sort, :order_by