def METHOD_NAME(doc):
    states = list(doc.states.values_list("pk", flat=True))
    rules = SearchRule.objects.none()
    if doc.group_id:
        groups = [doc.group_id]
        if doc.group.parent_id:
            groups.append(doc.group.parent_id)
        rules |= SearchRule.objects.filter(
            rule_type__in=['group', 'area', 'group_rfc', 'area_rfc', 'group_exp'],
            state__in=states,
            group__in=groups
        )
    rules |= SearchRule.objects.filter(
        rule_type__in=['state_iab', 'state_iana', 'state_iesg', 'state_irtf', 'state_ise', 'state_rfceditor', 'state_ietf'],
        state__in=states,
    )
    rules |= SearchRule.objects.filter(
        rule_type__in=["author", "author_rfc"],
        state__in=states,
        person__in=list(Person.objects.filter(documentauthor__document=doc)),
    )
    if doc.ad_id:
        rules |= SearchRule.objects.filter(
            rule_type="ad",
            state__in=states,
            person=doc.ad_id,
        )
    if doc.shepherd_id:
        rules |= SearchRule.objects.filter(
            rule_type="shepherd",
            state__in=states,
            person__email=doc.shepherd_id,
        )
    rules |= SearchRule.objects.filter(
        rule_type="name_contains",
        state__in=states,
        name_contains_index=doc, # search our materialized index to avoid full scan
    )
    return rules