Ejemplo n.º 1
0
 public void AddFilter(Filter f)
 => Filters.Add(new QueryParserResponseFilterInfo
 {
     Type                = f.GetType().Name,
     Cost                = f.Cost,
     FilterText          = f.GetQueryText(),
     Mode                = f.FilterMode,
     RequiresResultInput = f.RequiresResultInput,
     RequiresTextInput   = f.RequiresTextInput,
     RequiresStreamInput = f.RequiresStreamInput,
     SubQueryDetails     = f.IsSubQuery ? QueryParserResponse.Create((f as ISubQuery).Query.OriginalQueryText) : null
 });
Ejemplo n.º 2
0
        public HttpResponseMessage GetQueryParserOutput([FromBody] JsonQuery jsonQuery)
        {
            try
            {
                var response = QueryParserResponse.Create(jsonQuery.QueryText);

                return(CreateOKResponse(response));
            }
            catch (Exception ex)
            {
                Utility.LogException(ex);
                if (ex is ReflectionTypeLoadException rex)
                {
                    Utility.LogException(rex.LoaderExceptions.First());
                }
                return(CreateExceptionResponse(ex));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a QueryParserResponse from a query text string
        /// </summary>
        /// <param name="queryText"></param>
        /// <returns></returns>
        public static QueryParserResponse Create(string queryText)
        {
            var r = new QueryParserResponse();

            r.OriginalQueryText = queryText;

            try
            {
                var query = new Query(queryText);

                r.Tokens.AddRange(Query.TokeniseQueryText(queryText));
                r.Filters = new List <QueryParserResponseFilterInfo>();
                foreach (var f in query.Filters.OrderBy(x => x.Cost * x.FilterModeCostAdjustmentFactor))
                {
                    r.AddFilter(f);
                }
                foreach (var f in query.Taggers.OrderBy(x => x.Cost))
                {
                    r.AddFilter(f);
                }

                r.ParsedQueryText = query.ToString();

                r.EstimatedMaxCost  = query.Filters.Aggregate(0m, (x, y) => x + y.Cost * y.FilterModeCostAdjustmentFactor);
                r.EstimatedMaxCost += query.Taggers.Aggregate(0m, (x, y) => x + y.Cost);

                r.RequiresResultInput = query.RequiresResultInput;
                r.RequiresTextInput   = query.RequiresTextInput;
                r.RequiresStreamInput = query.RequiresStreamInput;
                r.Success             = true;
            }
            catch (Exception ex)
            {
                r.Success     = false;
                r.ErrorReason = ex.Message;
                Utility.LogException(ex);
            }

            return(r);
        }