def _parse_facets(self): """ Parses the facet counts into this Result's facets list. """ result = self._get_result_node() facets = xmlutils.get_sibling_node(result, "lst", "facet_counts") if not facets: return None fields = xmlutils.get_child_node(facets, "lst", "facet_fields") if not fields: return None exceptions = xmlutils.get_child_node(facets, 'str') if exceptions: raise SolrException('There was a java exception: %s' % exceptions.lastChild.wholeText) for facet in xmlutils.get_child_nodes(fields, "lst"): self.facets.append(Facet(facet)) params = self.header.get('params', None) if params is not None: self.date_gap = params.get('facet.date.gap', '+1YEAR') # default to a 1 year gap facet_dates = xmlutils.get_child_node(facets, "lst", "facet_dates") for facet_date in xmlutils.get_child_nodes(facet_dates, "lst"): self.facets.append(DateFacet(facet_date, self.date_gap))
def _parse_results(self): """ Parse the results array into the documents list. Each resulting document element is a dictionary. """ result = self._get_result_node() if not result: raise ValueError, "Results contained no result." self.count = int(xmlutils.get_attribute(result, "numFound")) for d in xmlutils.get_child_nodes(result, "doc"): data_dict = xmlutils.get_dictionary(d) document = registry[data_dict['model']](data_dict) self.documents.append(document)
def _parse_facets(self): """ Parses the facet counts into this Result's facets list. """ result = self._get_result_node() facets = xmlutils.get_sibling_node(result, "lst", "facet_counts") if not facets: return None fields = xmlutils.get_child_node(facets, "lst", "facet_fields") if not fields: return None for facet in xmlutils.get_child_nodes(fields, "lst"): self.facets.append(Facet(facet))
def __init__(self, node): """ Iterate the provided DOM Node, parsing the facet name and any child value counts. Facet values are additionally merged into a tree structure based on common name prefixes, and then flattened out again. This allows for parent-child relationships and nested value counts. See merge_values. Parses the facet counts into this Result's facets list. Takes a parsed xml document. """ (self.name, self.values) = (xmlutils.get_attribute(node, "name"), []) for c in xmlutils.get_child_nodes(node, "int"): value = xmlutils.get_attribute(c, "name") count = xmlutils.get_int(c) self.values.append(self.create_value(value, count)) self.merge_values()