def METHOD_NAME(exclude_const, index):
    """Build index for job state points.
    Parameters
    ----------
    exclude_const : bool
        Excludes state point keys whose values are constant across the index.
    index : _SearchIndexer
        A _SearchIndexer mapping from job ids to job state points.
    Yields
    ------
    statepoint_key : str
        State point key.
    statepoint_values : dict
        Dictionary mapping from a state point value to the set of job ids with
        that state point value.
    """
    indexes = {}
    for _id in index.find():
        doc = index[_id]
        for key, _ in _nested_dicts_to_dotted_keys(doc):
            if key.split(".")[0] == "sp":
                indexes[key] = index.build_index(key)
    for key in sorted(indexes, key=lambda key: (len(indexes[key]), key)):
        if (
            exclude_const
            and len(indexes[key]) == 1
            and len(indexes[key][next(indexes[key].keys())]) == len(index)
        ):
            continue
        statepoint_key = _strip_prefix(key)
        # Remove _DictPlaceholder keys from the index
        statepoint_values = indexes[key]
        statepoint_values.pop(_DictPlaceholder, None)
        yield statepoint_key, statepoint_values