/// <summary> /// Sets the query configuration handler that will be used during query /// processing. It can be <c>null</c>. It's also set to the processor /// returned by <see cref="QueryNodeProcessor"/>. /// </summary> /// <param name="config">the query configuration handler used during query processing, it /// can be <c>null</c></param> /// <seealso cref="QueryConfigHandler"/> /// <seealso cref="Config.QueryConfigHandler"/> public virtual void SetQueryConfigHandler(QueryConfigHandler config) { this.config = config; IQueryNodeProcessor processor = QueryNodeProcessor; if (processor != null) { processor.SetQueryConfigHandler(config); } }
/// <summary> /// Creates a query parser helper object using the specified configuration, /// text parser, processor and builder. /// </summary> /// <param name="queryConfigHandler">the query configuration handler that will be initially set to this helper</param> /// <param name="syntaxParser">the text parser that will be initially set to this helper</param> /// <param name="processor">the query processor that will be initially set to this helper</param> /// <param name="builder">the query builder that will be initially set to this helper</param> /// <seealso cref="IQueryNodeProcessor"/> /// <seealso cref="ISyntaxParser"/> /// <seealso cref="IQueryBuilder{TQuery}"/> /// <seealso cref="Config.QueryConfigHandler"/> public QueryParserHelper(QueryConfigHandler queryConfigHandler, ISyntaxParser syntaxParser, IQueryNodeProcessor processor, IQueryBuilder <TQuery> builder) { this.syntaxParser = syntaxParser; this.config = queryConfigHandler; this.processor = processor; this.builder = builder; if (processor != null) { processor.SetQueryConfigHandler(queryConfigHandler); } }
/// <summary> /// Parses a query string to an object, usually some query object. /// <para/> /// In this method the three phases are executed: /// <para/> /// <list type="number"> /// <item><description> /// the query string is parsed using the /// text parser returned by <see cref="SyntaxParser"/>, the result is a query /// node tree. /// </description></item> /// <item><description> /// the query node tree is processed by the /// processor returned by <see cref="QueryNodeProcessor"/>. /// </description></item> /// <item><description> /// a object is built from the query node /// tree using the builder returned by <see cref="QueryBuilder"/>. /// </description></item> /// </list> /// </summary> /// <param name="query">the query string</param> /// <param name="defaultField">the default field used by the text parser</param> /// <returns>the object built from the query</returns> /// <exception cref="QueryNodeException">if something wrong happens along the three phases</exception> public virtual TQuery Parse(string query, string defaultField) { IQueryNode queryTree = SyntaxParser.Parse(query, defaultField); IQueryNodeProcessor processor = QueryNodeProcessor; if (processor != null) { queryTree = processor.Process(queryTree); } return(QueryBuilder.Build(queryTree)); }
/// <summary> /// Sets the processor that will be used to process the query node tree. If /// there is any <see cref="Config.QueryConfigHandler"/> returned by /// <see cref="QueryConfigHandler"/>, it will be set on the processor. The /// argument can be <c>null</c>, which means that no processor will be /// used to process the query node tree. /// </summary> /// <param name="processor">the processor that will be used to process the query node tree, /// this argument can be <c>null</c></param> /// <seealso cref="QueryNodeProcessor"/> /// <seealso cref="IQueryNodeProcessor"/> public virtual void SetQueryNodeProcessor(IQueryNodeProcessor processor) { this.processor = processor; this.processor.SetQueryConfigHandler(QueryConfigHandler); }