class BaseEditorSearchIndex implements EditorSearchIndex<T> {

    @Override
    public void search(final String term) {

        triggerClearCurrentResultsCallback();
        final boolean isNewSearch = !Objects.equals(term, currentTerm) || isDirty();
        final Optional<T> result;

        if (isNewSearch) {
            loadSearchResults(term);
            result = getFirstSearchResult();
        } else {
            result = findNextElement();
        }

        currentResult = result.orElse(null);
        currentTerm = term;

        triggerOnFoundCommand();
        triggerOnSearchPerformedCommand();
    }

}