internal TrieNodeStructSearchResult SearchLastNode(long parentPosition, string keyword)
        {
            var result = TrieNodeStructSearchResult.CreateNotFound();

            long currentPosition = parentPosition;

            for (int i = 0; i < keyword.Length; i++)
            {
                long?childPosition = GetChildPositionFromNode(currentPosition, keyword[i]);

                if (childPosition != null)
                {
                    if (i == keyword.Length - 1)
                    {
                        result = TrieNodeStructSearchResult.CreateFoundEquals(childPosition.Value);
                        break;
                    }

                    currentPosition = childPosition.Value;
                    continue;
                }
                else
                {
                    if (i != 0)
                    {
                        result = TrieNodeStructSearchResult.CreateFoundStartsWith(currentPosition, i, currentPosition);
                    }

                    break;
                }
            }

            return(result);
        }
        public static TrieNodeStructSearchResult CreateNotFound()
        {
            var result = new TrieNodeStructSearchResult();

            result.Status = TrieNodeSearchResultType.NotFound;

            return(result);
        }
        public static TrieNodeStructSearchResult CreateFoundEquals(long lastFoundNodePosition)
        {
            var result = new TrieNodeStructSearchResult();

            result.Status = TrieNodeSearchResultType.FoundEquals;
            result.LastFoundNodePosition = lastFoundNodePosition;

            return(result);
        }
        public static TrieNodeStructSearchResult CreateFoundStartsWith(long absolutePosition, int lastFoundCharacterIndex, long lastFoundNodePosition)
        {
            var result = new TrieNodeStructSearchResult();

            result.Status                  = TrieNodeSearchResultType.FoundStartsWith;
            result.AbsolutePosition        = absolutePosition;
            result.LastFoundCharacterIndex = lastFoundCharacterIndex;
            result.LastFoundNodePosition   = lastFoundNodePosition;

            return(result);
        }
Esempio n. 5
0
        private SearchResult CreateResultFromNode(TrieBinaryReader trieBinaryReader, TrieNodeStructSearchResult node, string keyword, SearchOptions options)
        {
            var searchResult = new SearchResult();

            if (node.Status == TrieNodeSearchResultType.NotFound || node.Status == TrieNodeSearchResultType.Unkown)
            {
                searchResult.ResultType = node.Status;
                return(searchResult);
            }

            string prefix = null;

            if (node.Status == TrieNodeSearchResultType.FoundStartsWith)
            {
                if (!options.SuggestWhenFoundStartsWith)
                {
                    searchResult.ResultType = node.Status;
                    return(searchResult);
                }

                prefix = keyword.Substring(0, node.LastFoundCharacterIndex - 1);
            }
            else if (node.Status == TrieNodeSearchResultType.FoundEquals)
            {
                //prefix = input.Keyword.Substring(0, input.Keyword.Length - 1);
                if (GetTailStream() == null)
                {
                    prefix = keyword.Substring(0, keyword.Length - 1);
                }
                else
                {
                    prefix = keyword;
                }
            }

            searchResult.ResultType = node.Status;
            searchResult.Items      = trieBinaryReader.GetAutoCompleteNodes(
                node.LastFoundNodePosition,
                prefix,
                options.MaxItemCount,
                new List <string>(),
                GetTailStream()
                ).ToArray();

            return(searchResult);
        }