nodes: 0, module; 1, function_definition; 2, function_name:_get_final_set; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sets; 7, identifier:pk; 8, identifier:sort_options; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, comment:# if we have a slice and we want to sort by the score of a sorted set,; 13, comment:# as redis sort command doesn't handle this, we have to create keys for; 14, comment:# each value of the sorted set and sort on them; 15, comment:# @antirez, y u don't allow this !!??!!; 16, if_statement; 17, return_statement; 18, comment:"""
          Add intersects fo sets and call parent's _get_final_set.
          If we have to sort by sorted score, and we have a slice, we have to
          convert the whole sorted set to keys now.
          """; 19, subscript; 20, comment:# if the intersect method was called, we had new sets to intersect; 21, comment:# to the global set of sets.; 22, comment:# And it there is no real filters, we had the set of the whole; 23, comment:# collection because we cannot be sure that entries in "intersects"; 24, comment:# are all real primary keys; 25, block; 26, assignment; 27, boolean_operator; 28, comment:# TODO: if we have filters, maybe apply _zet_to_keys to only; 29, comment:#       intersected values; 30, block; 31, expression_list; 32, attribute; 33, string; 34, expression_statement; 35, expression_statement; 36, if_statement; 37, pattern_list; 38, call; 39, identifier:final_set; 40, attribute; 41, expression_statement; 42, comment:# new keys have to be deleted once the final sort is done; 43, if_statement; 44, expression_statement; 45, expression_statement; 46, identifier:final_set; 47, identifier:keys_to_delete_later; 48, identifier:self; 49, identifier:_lazy_collection; 50, string_content:intersects; 51, assignment; 52, call; 53, boolean_operator; 54, block; 55, identifier:final_set; 56, identifier:keys_to_delete_later; 57, attribute; 58, argument_list; 59, identifier:self; 60, identifier:_sort_by_sortedset_before; 61, assignment; 62, not_operator; 63, block; 64, call; 65, augmented_assignment; 66, identifier:sets; 67, subscript; 68, attribute; 69, argument_list; 70, not_operator; 71, not_operator; 72, expression_statement; 73, call; 74, identifier:_get_final_set; 75, identifier:sets; 76, identifier:pk; 77, identifier:sort_options; 78, pattern_list; 79, call; 80, identifier:keys_to_delete_later; 81, expression_statement; 82, attribute; 83, argument_list; 84, identifier:keys_to_delete_later; 85, identifier:tmp_keys; 86, identifier:sets; 87, slice; 88, identifier:sets; 89, identifier:extend; 90, subscript; 91, subscript; 92, attribute; 93, call; 94, identifier:super; 95, argument_list; 96, identifier:base_tmp_key; 97, identifier:tmp_keys; 98, attribute; 99, argument_list; 100, assignment; 101, identifier:keys_to_delete_later; 102, identifier:append; 103, identifier:base_tmp_key; 104, attribute; 105, string; 106, attribute; 107, string; 108, identifier:self; 109, identifier:stored_key; 110, attribute; 111, argument_list; 112, identifier:ExtendedCollectionManager; 113, identifier:self; 114, identifier:self; 115, identifier:_prepare_sort_by_score; 116, None; 117, identifier:sort_options; 118, identifier:keys_to_delete_later; 119, list; 120, identifier:self; 121, identifier:_lazy_collection; 122, string_content:intersects; 123, identifier:self; 124, identifier:_lazy_collection; 125, string_content:sets; 126, identifier:sets; 127, identifier:append; 128, attribute; 129, call; 130, identifier:collection_key; 131, attribute; 132, argument_list; 133, attribute; 134, identifier:get_field; 135, string; 136, identifier:self; 137, identifier:cls; 138, string_content:pk
code: def _get_final_set(self, sets, pk, sort_options):
          """
          Add intersects fo sets and call parent's _get_final_set.
          If we have to sort by sorted score, and we have a slice, we have to
          convert the whole sorted set to keys now.
          """
          if self._lazy_collection['intersects']:
              # if the intersect method was called, we had new sets to intersect
              # to the global set of sets.
              # And it there is no real filters, we had the set of the whole
              # collection because we cannot be sure that entries in "intersects"
              # are all real primary keys
              sets = sets[::]
              sets.extend(self._lazy_collection['intersects'])
              if not self._lazy_collection['sets'] and not self.stored_key:
                  sets.append(self.cls.get_field('pk').collection_key)
  
          final_set, keys_to_delete_later = super(ExtendedCollectionManager,
                                      self)._get_final_set(sets, pk, sort_options)
  
          # if we have a slice and we want to sort by the score of a sorted set,
          # as redis sort command doesn't handle this, we have to create keys for
          # each value of the sorted set and sort on them
          # @antirez, y u don't allow this !!??!!
          if final_set and self._sort_by_sortedset_before:
              # TODO: if we have filters, maybe apply _zet_to_keys to only
              #       intersected values
              base_tmp_key, tmp_keys = self._prepare_sort_by_score(None, sort_options)
              # new keys have to be deleted once the final sort is done
              if not keys_to_delete_later:
                  keys_to_delete_later = []
              keys_to_delete_later.append(base_tmp_key)
              keys_to_delete_later += tmp_keys
  
          return final_set, keys_to_delete_later