public function clearObsoleteClasses($classes)
    {
        if (empty($classes)) {
            return false;
        }

        // Delete all records which do not match the necessary classname rules
        $conditions = array();
        foreach ($classes as $class => $options) {
            if ($options['include_children']) {
                $conditions[] = "ClassHierarchy:{$class}";
            } else {
                $conditions[] = "ClassName:{$class}";
            }
        }

        // Delete records which don't match any of these conditions in this index
        $deleteQuery = "-(" . implode(' ', $conditions) . ")";
        $this
            ->getService()
            ->deleteByQuery($deleteQuery);
        return true;
    }