예제 #1
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);

            Logging.Logger.Instance.Info(String.Format("Result FQL After - Build: {0}", resultFql), Logging.DiagnosticsCategories.eCaseSearch);
            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();
                Logging.Logger.Instance.Info(String.Format("Result FQL After - Synonyms and Boost Value Added: {0}", resultFql), Logging.DiagnosticsCategories.eCaseSearch);
            }
            if (!string.IsNullOrEmpty(_scopeFilter))
            {
                resultFql += " AND filter(" + _scopeFilter + ")";
                Logging.Logger.Instance.Info(String.Format("Result FQL After - Scope Filter Added: {0}", resultFql), Logging.DiagnosticsCategories.eCaseSearch);
            }
            return(resultFql);
        }
예제 #2
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);
        }
예제 #3
0
        internal void CreateTokenFql(TokenBuilder builder, List <string> includes, List <string> excludes, SynonymHandling synonymHandling)
        {
            string ors = JoinTokens(builder.OrExpr, "or");

            if (!string.IsNullOrEmpty(ors))
            {
                includes.Add(ors);
            }
            foreach (Token token in builder.AndExpr)
            {
                string fql = token.GetFql(synonymHandling, _synonymLookup, _managedTypes);
                if (synonymHandling == SynonymHandling.Include && (token.Type == TokenType.Phrase || token.Type == TokenType.Word))
                {
                    fql = GetSynonymsFql(token.Text, fql);
                }
                includes.Add(fql);
            }
            foreach (Token token in builder.NotExpr)
            {
                excludes.Add(token.GetFql(SynonymHandling.None, null, _managedTypes));
            }
        }