Exemple #1
0
        public IEnumerable <SearchResult> FindNodes(string query)
        {
            var matcher = new NodeQueryMarcher(query, build.StringTable.Instances);

            resultSet = new List <SearchResult>();

            var cts = new CancellationTokenSource();

            build.VisitAllChildren <object>(node => Visit(node, matcher, cts), cts.Token);

            if (matcher.Under != null)
            {
                matcher = new NodeQueryMarcher(matcher.Under, build.StringTable.Instances);

                for (int i = resultSet.Count - 1; i >= 0; i--)
                {
                    var result = resultSet[i];
                    if (!IsUnder(matcher, result))
                    {
                        resultSet.RemoveAt(i);
                    }
                }
            }

            return(resultSet);
        }
Exemple #2
0
        private bool IsUnder(NodeQueryMarcher matcher, SearchResult result)
        {
            if (!(result.Node is ParentedNode parented))
            {
                return(true);
            }

            foreach (var parent in parented.GetParentChain())
            {
                if (matcher.IsMatch(parent) != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private void Visit(object node, NodeQueryMarcher matcher, CancellationTokenSource cancellationTokenSource)
        {
            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            if (resultSet.Count > MaxResults)
            {
                cancellationTokenSource.Cancel();
                return;
            }

            var result = matcher.IsMatch(node);

            if (result != null)
            {
                result.Node = node;
                resultSet.Add(result);
            }
        }