Skip to content

Commit

Permalink
Implemented the RDF::Query#optimize and #optimize! methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Dec 12, 2010
1 parent 549a3d8 commit f9adf50
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/rdf/query.rb
Expand Up @@ -153,6 +153,33 @@ def pattern(pattern, options = {})
self
end

##
# Returns an optimized copy of this query.
#
# @param [Hash{Symbol => Object}] options
# any additional options for optimization
# @return [RDF::Query] a copy of `self`
# @since 0.3.0
def optimize(options = {})
self.dup.optimize!(options)
end

##
# Optimizes this query by reordering its constituent triple patterns
# according to their cost estimates.
#
# @param [Hash{Symbol => Object}] options
# any additional options for optimization
# @return [void] `self`
# @see RDF::Query::Pattern#cost
# @since 0.3.0
def optimize!(options = {})
@patterns.sort! do |a, b|
(a.cost || 0) <=> (b.cost || 0)
end
self
end

##
# Executes this query on the given `queryable` graph or repository.
#
Expand Down

0 comments on commit f9adf50

Please sign in to comment.