Exemplo n.º 1
0
        public string GetFqlFromKql(string kql)
        {
            const TokenType allowedTokenTypes = TokenType.Group | TokenType.Phrase | TokenType.Property | TokenType.Word | TokenType.Operator;
            TokenBuilder    builder           = new TokenBuilder(kql, allowedTokenTypes);

            builder.Build();
            List <string> includes = new List <string>();
            List <string> excludes = new List <string>();

            CreateTokenFql(builder, includes, excludes, SynonymHandling.None);
            return(Build(includes, excludes));
        }
Exemplo n.º 2
0
        public string GetFqlFromKql(string kql, SynonymHandling synonymHandling, int boostValue)
        {
            _synonymHandling = synonymHandling;
            const TokenType allowedTokenTypes = TokenType.Group | TokenType.Phrase | TokenType.Property | TokenType.Word | TokenType.Operator;
            TokenBuilder    builder           = new TokenBuilder(kql, allowedTokenTypes);

            builder.Build();
            List <string> includes = new List <string>();
            List <string> excludes = new List <string>();

            CreateTokenFql(builder, includes, excludes, synonymHandling);
            string        resultFql = Build(includes, excludes);
            StringBuilder sb        = new StringBuilder();

            if (_synonymAdded && boostValue > 0)
            {
                sb.Append("xrank(");
                sb.Append(resultFql);
                sb.Append(",");
                if (includes.Count > 1)
                {
                    sb.Append("and(");
                }
                includes.Clear();
                excludes.Clear();
                CreateTokenFql(builder, includes, excludes, SynonymHandling.None);
                sb.Append(Build(includes, new List <string>()).Replace("annotation_class=\"user\",", ""));
                if (includes.Count > 1)
                {
                    sb.Append(")");
                }
                sb.AppendFormat(",boost={0})", boostValue); // close xrank
                resultFql = sb.ToString();
            }
            if (!string.IsNullOrEmpty(_scopeFilter))
            {
                resultFql += " AND filter(" + _scopeFilter + ")";
            }
            return(resultFql);
        }
Exemplo n.º 3
0
        public string GetFql(SynonymHandling synonymHandling, Dictionary <string, List <string> > synonymLookup, Dictionary <string, string> propertyTypeLookup)
        {
            if (Type == TokenType.Phrase || Type == TokenType.Word || Type == TokenType.Property)
            {
                FqlHelper helper = new FqlHelper(synonymLookup, propertyTypeLookup, null);
                return(helper.GetFqlQueryForTerm(this));
            }
            else if (Type == TokenType.Group)
            {
                Text = Text.Trim(new char[] { '(', ')', ' ' });
                TokenType allowed;
                if (ParentOperator == "ANY" || ParentOperator == "ALL" && ParentOperator == "NONE" && ParentOperator == "NOT")
                {
                    allowed = TokenType.Phrase | TokenType.Property | TokenType.Word;
                }
                else
                {
                    allowed = TokenType.Phrase | TokenType.Property | TokenType.Word | TokenType.Operator;
                }
                TokenBuilder builder = new TokenBuilder(Text, allowed);
                builder.Build();

                if (ParentOperator == "ANY")
                {
                    builder.OrExpr.AddRange(builder.AndExpr);
                    builder.AndExpr.Clear();
                }

                List <string> includes = new List <string>();
                List <string> excludes = new List <string>();
                FqlHelper     helper   = new FqlHelper(synonymLookup, propertyTypeLookup, null);
                helper.CreateTokenFql(builder, includes, excludes, synonymHandling);
                return(helper.Build(includes, excludes));
            }
            return(string.Empty);
        }