Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

chef-solor-search: using latests upstream version of this library to …

…make search usable in other places than recipes and definitions
  • Loading branch information...
commit 55c5ada8ccbac50ccef77c9c2c95bf04670663c9 1 parent e1f53f0
@thekorn thekorn authored
Showing with 35 additions and 34 deletions.
  1. +35 −34 littlechef/search.rb
View
69 littlechef/search.rb
@@ -36,46 +36,47 @@ def require_relative(relative_feature)
require_relative 'parser.rb'
class Chef
- class Recipe
+ module Mixin
+ module Language
- # Overwrite the search method of recipes to operate locally by using
- # data found in data_bags.
- # Only very basic lucene syntax is supported and also sorting the result
- # is not implemented, if this search method does not support a given query
- # an exception is raised.
- # This search() method returns a block iterator or an Array, depending
- # on how this method is called.
- def search(bag_name, query=nil, sort=nil, start=0, rows=1000, &block)
- if !sort.nil?
- raise "Sorting search results is not supported"
- end
- @_query = Query.parse(query)
- if @_query.nil?
- raise "Query #{query} is not supported"
- end
- if block_given?
- pos = 0
- else
- result = []
- end
- data_bag(bag_name.to_s).each do |bag_item_id|
- bag_item = data_bag_item(bag_name.to_s, bag_item_id)
- if @_query.match(bag_item)
- if block_given?
- if (pos >= start and pos < (start + rows))
- yield bag_item
+ # Overwrite the search method of recipes to operate locally by using
+ # data found in data_bags.
+ # Only very basic lucene syntax is supported and also sorting the result
+ # is not implemented, if this search method does not support a given query
+ # an exception is raised.
+ # This search() method returns a block iterator or an Array, depending
+ # on how this method is called.
+ def search(bag_name, query=nil, sort=nil, start=0, rows=1000, &block)
+ if !sort.nil?
+ raise "Sorting search results is not supported"
+ end
+ @_query = Query.parse(query)
+ if @_query.nil?
+ raise "Query #{query} is not supported"
+ end
+ if block_given?
+ pos = 0
+ else
+ result = []
+ end
+ data_bag(bag_name.to_s).each do |bag_item_id|
+ bag_item = data_bag_item(bag_name.to_s, bag_item_id)
+ if @_query.match(bag_item)
+ if block_given?
+ if (pos >= start and pos < (start + rows))
+ yield bag_item
+ end
+ pos += 1
+ else
+ result << bag_item
end
- pos += 1
- else
- result << bag_item
end
end
- end
- if !block_given?
- return result.slice(start, rows)
+ if !block_given?
+ return result.slice(start, rows)
+ end
end
end
end
end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.