def METHOD_NAME(cls, session: db.Session, device: Device):
    """(Re)Generates the device search tokens."""
    assert not isinstance(device, Component)
    tokens = [
        (str(device.id), search.Weight.A),
        (inflection.humanize(device.type), search.Weight.B),
        (Device.model, search.Weight.B),
        (Device.manufacturer, search.Weight.C),
        (Device.serial_number, search.Weight.A)
    ]
    if device.manufacturer:
        # todo this has to be done using a dictionary
        manufacturer = device.manufacturer.lower()
        if 'asus' in manufacturer:
            tokens.append(('asus', search.Weight.B))
        if 'hewlett' in manufacturer or 'hp' in manufacturer or 'h.p' in manufacturer:
            tokens.append(('hp', search.Weight.B))
            tokens.append(('h.p', search.Weight.C))
            tokens.append(('hewlett', search.Weight.C))
            tokens.append(('packard', search.Weight.C))
    if isinstance(device, Computer):
        # Aggregate the values of all the components of pc
        Comp = aliased(Component)
        tokens.extend((
            (db.func.string_agg(db.cast(Comp.id, db.TEXT), ' '), search.Weight.D),
            (db.func.string_agg(Comp.model, ' '), search.Weight.C),
            (db.func.string_agg(Comp.manufacturer, ' '), search.Weight.D),
            (db.func.string_agg(Comp.serial_number, ' '), search.Weight.B),
            (db.func.string_agg(Comp.type, ' '), search.Weight.B),
            ('Computer', search.Weight.C),
            ('PC', search.Weight.C),
        ))
    properties = session \
        .query(search.Search.vectorize(*tokens)) \
        .filter(Device.id == device.id)
    if isinstance(device, Computer):
        # Join to components
        properties = properties \
            .outerjoin(Comp, Computer.components) \
            .group_by(Device.id)
    tags = session.query(
        search.Search.vectorize(
            (db.func.string_agg(Tag.id, ' '), search.Weight.A),
            (db.func.string_agg(Tag.secondary, ' '), search.Weight.A),
            (db.func.string_agg(Organization.name, ' '), search.Weight.B)
        )
    ).filter(Tag.device_id == device.id).join(Tag.org)
    devicehub_ids = session.query(
        search.Search.vectorize(
            (db.func.string_agg(Device.devicehub_id, ' '), search.Weight.A),
        )
    ).filter(Device.devicehub_id == device.devicehub_id)
    # Note that commit flushes later
    # todo see how to get rid of the one_or_none() by embedding those as subqueries
    # I don't like this but I want the 'on_conflict_on_update' thingie
    device_document = dict(properties=properties.one_or_none(), tags=tags.one_or_none(), devicehub_ids=devicehub_ids.one_or_none())
    insert = postgresql.insert(DeviceSearch.__table__) \
        .values(device_id=device.id, **device_document) \
        .on_conflict_do_update(constraint='device_search_pkey', set_=device_document)
    session.execute(insert)