示例#1
0
        public static SplittingQuery GetSimpleQuery(string query, Lib.Searching.Rules.IRule[] rules)
        {
            var fixedQuery = Tools.FixInvalidQuery(query, rules) ?? "";
            var sq         = SplittingQuery.SplitQuery(fixedQuery);

            return(GetSimpleQuery(sq, rules));
        }
示例#2
0
        public static SplittingQuery GetSimpleQuery(Searching.SplittingQuery sq, Lib.Searching.Rules.IRule[] rules)
        {
            SplittingQuery finalSq = new SplittingQuery();

            if (rules.Count() == 0)
            {
                finalSq = sq;
            }

            Dictionary <int, Rules.RuleResult> queryPartResults = new Dictionary <int, Rules.RuleResult>();

            for (int qi = 0; qi < sq.Parts.Length; qi++)
            {
                //beru cast dotazu
                queryPartResults.Add(qi, new Rules.RuleResult());

                //aplikuju na nej jednotliva pravidla, nasledujici na vysledek predchoziho
                SplittingQuery.Part[]   qToProcess = null;
                List <Rules.RuleResult> qpResults  = new List <Rules.RuleResult>();
                foreach (var rule in rules)
                {
                    qToProcess = qToProcess ?? new SplittingQuery.Part[] { sq.Parts[qi] };
                    qpResults  = new List <Rules.RuleResult>();
                    foreach (var qp in qToProcess)
                    {
                        var partRest = rule.Process(qp);
                        if (partRest != null)
                        {
                            qpResults.Add(partRest);
                        }
                        else
                        {
                            qpResults.Add(new Rules.RuleResult(qp, rule.NextStep));
                        }
                    }
                    if (qpResults.Last().NextStep == Rules.NextStepEnum.StopFurtherProcessing)
                    {
                        break;
                    }

                    qToProcess = qpResults
                                 .SelectMany(m => m.Query.Parts)
                                 .Where(m => m.ToQueryString.Length > 0)
                                 .ToArray();
                } //rules

                queryPartResults[qi] = new Rules.RuleResult(new SplittingQuery(qToProcess), qpResults.LastOrDefault()?.NextStep ?? Rules.NextStepEnum.Finished);
            } //qi all query parts

            foreach (var qp in queryPartResults)
            {
                finalSq.AddParts(qp.Value.Query.Parts);
            }

            return(finalSq);
        }