@@ -36,28 +36,46 @@ class Search(collections.Sequence):
36
36
The only required argument is the index name to search (eg. node, role, etc).
37
37
The second, optional argument can be any Solr search query, with the same semantics
38
38
as Chef.
39
+ The third optional parameter can be a dictionary containing the parameters for a filtered
40
+ search (partial search); see https://docs.chef.io/api_chef_server.html#id76
39
41
40
42
Example::
41
43
42
44
for row in Search('node', 'roles:app'):
43
45
print row['roles']
44
46
print row.object.name
47
+
48
+ # or
49
+
50
+ filters = {
51
+ 'name': ['name'],
52
+ 'ip': ['ipaddress'],
53
+ 'kernel_version': ['kernel', 'version'],
54
+ }
55
+
56
+ for row in Search('node', 'roles:app', filters):
57
+ print row['data']['name']
58
+ print row['data']['kernel_version']
45
59
46
60
.. versionadded:: 0.1
47
61
"""
48
62
49
63
url = '/search'
50
64
51
- def __init__ (self , index , q = '*:*' , rows = 1000 , start = 0 , api = None ):
65
+ def __init__ (self , index , q = '*:*' , rows = 1000 , start = 0 , api = None , filter_result = None ):
52
66
self .name = index
53
67
self .api = api or ChefAPI .get_global ()
54
68
self ._args = dict (q = q , rows = rows , start = start )
69
+ self .filter_result = filter_result
55
70
self .url = self .__class__ .url + '/' + self .name + '?' + six .moves .urllib .parse .urlencode (self ._args )
56
71
57
72
@property
58
73
def data (self ):
59
74
if not hasattr (self , '_data' ):
60
- self ._data = self .api [self .url ]
75
+ if self .filter_result is None :
76
+ self ._data = self .api .api_request ('GET' , self .url )
77
+ else :
78
+ self ._data = self .api .api_request ('POST' , self .url , data = self .filter_result )
61
79
return self ._data
62
80
63
81
@property
0 commit comments