-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresults.py
73 lines (58 loc) · 2.12 KB
/
results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""
Simple set of extensible objects for easy handling of data returned from solr
Created by michal.domanski on 2009-02-24.
"""
from tools import filter_even, filter_odd
class Response:
@property
def time(self):
return self._header['QTime']
@property
def status(self):
return self._header['status']
@property
def params(self):
return self._header['params']
class SelectResponse(Response):
@property
def docs(self):
return self._response['docs']
@property
def hits(self):
return self._response['numFound']
@property
def facets(self):
return self._facets
def get_facet_as_dict(self, field_name):
"""
.. warning:: not properly tested yet
Return facets dict for a given field name, requires faceting parameters issued in query
"""
facet_list = self._facets['facet_fields'][field_name]
return dict(zip( filter_odd(facet_list), filter_even(facet_list)))
@property
def facet_fields_dict(self):
"""
.. warning:: watchout, this may cost you some RAM
Builds a dict, where faceting field names are keys and faceting dicts are value, thus
creating a nested dict, requires faceting parameters issued in query
"""
loc_get_facet_as_dict = self.x_get_facet_as_dict
f_keys = self._facets['facet_fields'].keys()
return dict(zip(f_keys, map(loc_get_facet_as_dict, f_keys)))
@property
def stats(self):
return self._stats