Beispiel #1
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)
Beispiel #2
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()
Beispiel #3
0
 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)
Beispiel #4
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)