def match(httpreq: Request, request: AnalysisRequest) -> AnalysisResponse:
    """Fetches neighbors for a given Yeti Object."""

    entities = []  # type: list[tuple[graph.Relationship, entity.Entity]]
    seen_entities = set()
    observables = []  # type: list[tuple[graph.Relationship, observable.Observable]]

    unknown = set(request.observables)
    known = {}  # type: dict[str, observable.Observable]
    if request.add_unknown and httpreq.state.user.has_global_role(
        roles.Permission.WRITE
    ):
        for value in request.observables:
            try:
                observable.save(
                    tags=request.add_tags, value=value, type=request.add_type
                )
            except ValueError:
                continue
            unknown.discard(value)

    operator = "value__in"
    if request.regex_match:
        operator = "value__in~"
    db_observables, _ = observable.Observable.filter(
        query_args={operator: request.observables},
        wildcard=False,
        user=httpreq.state.user,
    )
    for db_observable in db_observables:
        known[db_observable.value] = db_observable
        unknown.discard(db_observable.value)
        processed_relationships = set()

        if request.fetch_neighbors:
            vertices, paths, _ = db_observable.neighbors(user=httpreq.state.user)
            for path in paths:
                edge = path[0]  # neighbors only returns 1 hop max by default
                if edge.id in processed_relationships:
                    continue

                if edge.target == db_observable.extended_id:
                    other = vertices[edge.source]
                else:
                    other = vertices[edge.target]

                if isinstance(other, entity.Entity):
                    if other.extended_id in seen_entities:
                        continue
                    entities.append((edge, other))
                    seen_entities.add(other.extended_id)
                if isinstance(other, observable.Observable):
                    observables.append((edge, other))

                processed_relationships.add(edge.id)

    matches = []
    for observable_string, indi in indicator.Regex.search(request.observables):
        matches.append((observable_string, indi))

    return AnalysisResponse(
        entities=entities,
        observables=observables,
        unknown=unknown,
        matches=matches,
        known=list(known.values()),
    )
Fetches neighbors for a given Yeti Object.
core/web/apiv2/graph.py