Esempio n. 1
0
 /// <summary>
 /// initialize an operation node
 /// </summary>
 /// <param name="relationNodes"></param>
 public QueryNode(QueryNode[] relationNodes)
     : this(QueryLogic.MUST, relationNodes)
 {
 }
Esempio n. 2
0
 /// <summary>
 /// create an operation node
 /// </summary>
 /// <param name="logic"></param>
 /// <param name="relateNodes"></param>
 /// <returns></returns>
 public static QueryNode CreateOperNode(QueryLogic logic, QueryNode[] relateNodes)
 {
     return new QueryNode(logic, relateNodes);
 }
Esempio n. 3
0
 /// <summary>
 /// initiaize an operation node
 /// </summary>
 /// <param name="logic"></param>
 /// <param name="relationNodes"></param>
 public QueryNode(QueryLogic logic, QueryNode[] relationNodes)
     : this(string.Empty, null, logic, QueryType.Operation)
 {
     this.RelationQuerys = relationNodes;
 }
Esempio n. 4
0
        /// <summary>
        /// 将分类规则解析为检索表达式树
        /// </summary>
        /// <param name="rule"></param>
        /// <returns></returns>
        public static QueryNode Analyser(RuleEntityOld rule)
        {
            QueryNode query = null;
            List<QueryNode> notQueries = new List<QueryNode>();

            // 构建非规则
            if (!string.IsNullOrEmpty(rule.TitleRemoveRuleExpression))
            {
                notQueries.Add(new QueryNode("Title", new ImmideatelyValue(rule.TitleRemoveRuleExpression)));
            }
            if (!string.IsNullOrEmpty(rule.ContentRemoveRuleExpression))
            {
                notQueries.Add(new QueryNode("Content", new ImmideatelyValue(rule.ContentRemoveRuleExpression)));
            }
            QueryNode notQuery = new QueryNode(QueryLogic.MUST_NOT, notQueries.ToArray());

            // 构建匹配规则
            QueryLogic logic = rule.MatchMode == MatchModeStyle.TitleAndContent ? QueryLogic.MUST : QueryLogic.SHOULD;
            if (!string.IsNullOrEmpty(rule.TitleRuleExpression) && !string.IsNullOrEmpty(rule.ContentRuleExpression))
            {
                query = new QueryNode(
                                logic,
                                new QueryNode[]
                                {
                                    new QueryNode("Title", new Query.Expression.FieldValue.ImmideatelyValue(rule.TitleRuleExpression)),
                                    new QueryNode("Content", new Query.Expression.FieldValue.ImmideatelyValue(rule.ContentRuleExpression))
                                });
            }
            else
            {
                List<QueryNode> querys = new List<QueryNode>();
                if (!string.IsNullOrEmpty(rule.TitleRuleExpression))
                {
                    querys.Add(new QueryNode("Title", new ImmideatelyValue(rule.TitleRuleExpression)));
                }
                if (!string.IsNullOrEmpty(rule.ContentRuleExpression))
                {
                    querys.Add(new QueryNode("Content", new ImmideatelyValue(rule.ContentRuleExpression)));
                }

                query = new QueryNode(logic, querys.ToArray());
            }

            // 处理其他查询条件,如时间,如站点
            List<QueryNode> otherQuery = new List<QueryNode>();
            if (!string.IsNullOrEmpty(rule.SiteIDS))
            {
                string[] siteIds = null;
                try
                {
                    siteIds = rule.SiteIDS.Split(new char[] { ',' }).ToArray();
                }
                catch (Exception e)
                {
                    Console.WriteLine("站点ID格式有错");
                }

                if (siteIds != null)
                {
                    otherQuery.Add(
                        new QueryNode(
                            "SiteId",
                            new Collection(siteIds)
                        ));
                }
            }

            // 重新设置分类规则的时间
            ReSetRule(rule);

            otherQuery.Add(new QueryNode(
                "PublishOn",
                new Query.Expression.FieldValue.Range(
                    DateTimeConverter.TimeSpan4Minute(rule.BeginDate),
                    DateTimeConverter.TimeSpan4Minute(rule.EndDate),
                    true)));

            return new QueryNode(
                new List<QueryNode>(otherQuery)
                {
                    query,
                    notQuery
                }.ToArray());
        }