/// <inheritdoc cref="MorphologyProvider.RewriteQuery"/> public override string RewriteQuery ( string queryExpression ) { QueryManager manager = new QueryManager(); QAst ast = manager.ParseQuery(queryExpression); ast.Walk(_QueryWalker); string result = manager.SerializeAst(ast); return(result); }
private bool _QueryWalker ( [NotNull] QAst ast ) { string prefix = Prefix.ThrowIfNull("Prefix"); for (int i = 0; i < ast.Children.Count; i++) { QAst child = ast.Children[i]; QAstEntry entry = child as QAstEntry; if (entry != null) { if (entry.Expression.StartsWith(prefix) && entry.Ending == EndingKind.NoTrim) { string word = string.IsNullOrEmpty(prefix) ? entry.Expression : entry.Expression.Substring(prefix.Length); MorphologyEntry[] entries = FindWord(word); string[] flatten = Flatten(word, entries); if (flatten.Length > 1) { QAstParen paren = new QAstParen(); QAst newAst = _MakeAst(flatten, entry.Tags); paren.Children.Add(newAst); ast.Children[i] = paren; return(false); } } } } return(true); }