Esempio n. 1
0
        public static bool MatchBody(SqlIndex sqlIndex, string search, params Func <searchOpt, searchOpt>[] opts)
        {
            var opt = new searchOpt
            {
                regex           = false,
                word            = false,
                includesCaption = false,
            };

            foreach (var optfunc in opts)
            {
                opt = optfunc(opt);
            }

            if (SqlMacher.General(sqlIndex.Sql, search, opt) >= 0)
            {
                return(true);
            }

            if (opt.includesCaption && SqlMacher.General(sqlIndex.Title, search, opt) >= 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public static int General(string body, string search, searchOpt opt)
        {
            var wk_pattern = search;
            var regopt     = RegexOptions.None;

            if (!opt.regex)
            {
                wk_pattern = Regex.Escape(wk_pattern);
            }

            if (opt.word)
            {
                wk_pattern = "(^|\\W)(" + wk_pattern + ")($|\\W)";
            }

            if (opt.ignoreCase)
            {
                regopt |= RegexOptions.IgnoreCase;
            }

            var reg = new Regex(wk_pattern, regopt);

            var match = reg.Match(body);

            return(match.Success ? match.Index : -1);
        }