def annotate(self, *args, **kwargs):
obj = self._clone()<EOL>if args:<EOL><INDENT>for arg in args:<EOL><INDENT>if isinstance(arg, Facet):<EOL><INDENT>obj._facets.append(arg)<EOL><DEDENT>elif isinstance(arg, six.string_types):<EOL><INDENT>modifier = "<STR_LIT>"<EOL>tokens = arg.split("<STR_LIT>")<EOL>if len(tokens)><NUM_LIT:1> and tokens[-<NUM_LIT:1>] in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:date>"]:<EOL><INDENT>modifier=tokens[-<NUM_LIT:1>]<EOL>tokens=tokens[:-<NUM_LIT:1>]<EOL><DEDENT>field, djfield = self._django_to_es_field("<STR_LIT>".join(tokens))<EOL>if modifier=="<STR_LIT>":<EOL><INDENT>obj._facets.append(TermFacet(name=arg, field=field, **kwargs))<EOL><DEDENT>elif modifier=="<STR_LIT>":<EOL><INDENT>obj._facets.append(TermStatsFacet(name=arg, **kwargs))<EOL><DEDENT>elif modifier=="<STR_LIT>":<EOL><INDENT>obj._facets.append(StatisticalFacet(name=arg, field=field, **kwargs))<EOL><DEDENT>elif modifier=="<STR_LIT>":<EOL><INDENT>obj._facets.append(HistogramFacet(name=arg, field=field, **kwargs))<EOL><DEDENT>elif modifier=="<STR_LIT:date>":<EOL><INDENT>obj._facets.append(DateHistogramFacet(name=arg, field=field, **kwargs))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for name, field in kwargs.items():<EOL><INDENT>obj._facets.append(<EOL>TermFacet(field=field.replace(FIELD_SEPARATOR, "<STR_LIT:.>"), name=name.replace(FIELD_SEPARATOR, "<STR_LIT:.>")))<EOL><DEDENT><DEDENT>return obj<EOL>
Return a query set in which the returned objects have been annotated
with data aggregated from related fields.