code: def _sort_results(self, results):
          parents = []
          groups = []
          for result in results:
              if not self._in_list(parents, result.parent):
                  parents.append(result.parent)
                  groups.append([])
                  groups[len(groups) - 1].append(result)
              else:
                  groups[parents.index(result.parent)].append(result)
          array = []
          for group in groups:
              array += sorted(
                  group,
                  key=lambda element: element.parent.contents.index(element)
              )
          return array