protected function clearRecords(SolrIndex $indexInstance, $class, $groups = null, $group = null)
    {
        // Clear by classname
        $conditions = array("+(ClassHierarchy:{$class})");

        // If grouping, delete from this group only
        if ($groups) {
            $conditions[] = "+_query_:\"{!frange l={$group} u={$group}}mod(ID, {$groups})\"";
        }

        // Also filter by state (suffix on document ID)
        $query = new SearchQuery();
        SearchVariant::with($class)
            ->call('alterQuery', $query, $indexInstance);
        if ($query->isfiltered()) {
            $conditions = array_merge($conditions, $indexInstance->getFiltersComponent($query));
        }

        // Invoke delete on index
        $deleteQuery = implode(' ', $conditions);
        $indexInstance
            ->getService()
            ->deleteByQuery($deleteQuery);
    }