isOccurrenceMatching static method

bool isOccurrenceMatching(
  1. HierarchyOccurrence node,
  2. String? searchTerm
)

Check if an occurrence or any of its descendants match searchTerm.

The search term is split on / or . into hierarchical segments. Each segment is matched via substring containment against occurrence names at successive depths.

Returns true if searchTerm is null/empty, or if the occurrence (or a descendant) matches all segments in order.

This is useful for tree-view filtering: show an occurrence only when it or one of its descendants matches the user's query.

Implementation

static bool isOccurrenceMatching(
    HierarchyOccurrence node, String? searchTerm) {
  if (searchTerm == null || searchTerm.isEmpty) {
    return true;
  }

  final normalizedQuery = searchTerm.replaceAll('.', hierarchyPathSeparator);
  final queryParts = normalizedQuery
      .split(hierarchyPathSeparator)
      .map((s) => s.trim())
      .where((s) => s.isNotEmpty)
      .toList();

  return _isOccurrenceMatchingRecursive(node, queryParts, 0);
}