Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 def _parse_header(self):
     """
     Parses the results header into the header dictionary.
     """
     header = xmlutils.get_child_node(self._doc.firstChild, "lst", "responseHeader")
     
     if not header:
         raise ValueError, "Results contained no header."
     
     self.header = xmlutils.get_dictionary(header)
Ejemplo n.º 3
0
 def __init__(self, xml):
     """
     Parses the provided XML body and initialize the header dictionary.
     """
     if not xml:
         raise ValueError, "Invalid or missing XML"
     
     doc = minidom.parseString(xml)
     
     header = xmlutils.get_child_node(doc.firstChild, "lst", "responseHeader")
     
     self.header = xmlutils.get_dictionary(header)
     
     doc.unlink()
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
 def _parse_highlighting(self):
     """
     Parses the highlighting list into this Result's highlighting dictionary.
     Also iterate over this Result's documents, inserting highlighting
     elements to their owning documents.
     """
     highlighting = xmlutils.get_child_node(self._doc.firstChild, "lst", "highlighting")
     
     if not highlighting:
         return
     
     self.highlighting = xmlutils.get_dictionary(highlighting)
     for d in self.documents:
         #TODO: Ugly
         model_key = settings.SEARCH_SEPARATOR.join([d.fields['model'].value, d.pk_field.value])
         for key, value in self.highlighting[model_key].items():
             d.highlight += ' ' + ' '.join(value)
             d.fields[key].highlight = ' '.join(value)
Ejemplo n.º 6
0
 def _get_result_node(self):
     """
     Returns the result Node from this Result's DOM tree.
     """
     return xmlutils.get_child_node(self._doc.firstChild, "result")