protected override IQueryNode PreProcessNode(IQueryNode node) { if (node is FuzzyQueryNode fuzzyNode) { QueryConfigHandler config = GetQueryConfigHandler(); FuzzyConfig fuzzyConfig; // LUCENENET: IDE0059: Remove unnecessary value assignment if (config != null && (fuzzyConfig = config.Get(ConfigurationKeys.FUZZY_CONFIG)) != null) { fuzzyNode.PrefixLength = fuzzyConfig.PrefixLength; if (fuzzyNode.Similarity < 0) { fuzzyNode.Similarity = fuzzyConfig.MinSimilarity; } } else if (fuzzyNode.Similarity < 0) { throw new ArgumentException("No FUZZY_CONFIG set in the config"); } } return(node); }
public StandardQueryNodeProcessorPipeline(QueryConfigHandler queryConfig) : base(queryConfig) { Add(new WildcardQueryNodeProcessor()); Add(new MultiFieldQueryNodeProcessor()); Add(new FuzzyQueryNodeProcessor()); Add(new MatchAllDocsQueryNodeProcessor()); Add(new OpenRangeQueryNodeProcessor()); Add(new NumericQueryNodeProcessor()); Add(new NumericRangeQueryNodeProcessor()); Add(new LowercaseExpandedTermsQueryNodeProcessor()); Add(new TermRangeQueryNodeProcessor()); Add(new AllowLeadingWildcardProcessor()); Add(new AnalyzerQueryNodeProcessor()); Add(new PhraseSlopQueryNodeProcessor()); //add(new GroupQueryNodeProcessor()); Add(new BooleanQuery2ModifierNodeProcessor()); Add(new NoChildOptimizationQueryNodeProcessor()); Add(new RemoveDeletedQueryNodesProcessor()); Add(new RemoveEmptyNonLeafQueryNodeProcessor()); Add(new BooleanSingleChildOptimizationQueryNodeProcessor()); Add(new DefaultPhraseSlopQueryNodeProcessor()); Add(new BoostQueryNodeProcessor()); Add(new MultiTermRewriteMethodProcessor()); }
protected override IQueryNode PreProcessNode(IQueryNode node) { if (node is IFieldableNode) { IFieldableNode fieldNode = (IFieldableNode)node; QueryConfigHandler queryConfig = GetQueryConfigHandler(); if (queryConfig == null) { throw new ArgumentException( "A config handler is expected by the processor UniqueFieldQueryNodeProcessor!"); } if (!queryConfig.Has(SpansQueryConfigHandler.UNIQUE_FIELD)) { throw new ArgumentException( "UniqueFieldAttribute should be defined in the config handler!"); } String uniqueField = queryConfig.Get(SpansQueryConfigHandler.UNIQUE_FIELD); fieldNode.Field = (uniqueField); } return(node); }
protected override IQueryNode PreProcessNode(IQueryNode node) { if (node is FuzzyQueryNode) { FuzzyQueryNode fuzzyNode = (FuzzyQueryNode)node; QueryConfigHandler config = GetQueryConfigHandler(); FuzzyConfig fuzzyConfig = null; if (config != null && (fuzzyConfig = config.Get(ConfigurationKeys.FUZZY_CONFIG)) != null) { fuzzyNode.PrefixLength = fuzzyConfig.PrefixLength; if (fuzzyNode.Similarity < 0) { fuzzyNode.Similarity = fuzzyConfig.MinSimilarity; } } else if (fuzzyNode.Similarity < 0) { throw new ArgumentException("No FUZZY_CONFIG set in the config"); } } return(node); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is IFieldableNode fieldNode && (node.Parent == null || !(node.Parent is IFieldableNode))) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { string field = fieldNode.Field; FieldConfig fieldConfig = config.GetFieldConfig(StringUtils.ToString(field)); if (fieldConfig != null) { float?boost = fieldConfig.Get(ConfigurationKeys.BOOST); if (boost != null) { return(new BoostQueryNode(node, boost.Value)); } } } } return(node); }
/// <summary> /// For reference about this method check: /// <see cref="IQueryNodeProcessor.SetQueryConfigHandler(QueryConfigHandler)"/>. /// </summary> /// <param name="queryConfigHandler">the query configuration handler to be set.</param> /// <seealso cref="IQueryNodeProcessor.GetQueryConfigHandler()"/> /// <seealso cref="QueryConfigHandler"/> public virtual void SetQueryConfigHandler(QueryConfigHandler queryConfigHandler) { this.queryConfig = queryConfigHandler; foreach (IQueryNodeProcessor processor in this.processors) { processor.SetQueryConfigHandler(this.queryConfig); } }
/// <summary> /// Set the fields a query should be expanded to when the field is /// <c>null</c> /// </summary> /// <param name="fields">the fields used to expand the query</param> public virtual void SetMultiFields(string[] fields) { if (fields == null) { fields = new string[0]; } QueryConfigHandler.Set(ConfigurationKeys.MULTI_FIELDS, fields); }
/// <summary> /// Constructs a <see cref="NumericFieldConfigListener"/> object using the given <see cref="QueryConfigHandler"/>. /// </summary> /// <param name="config">the <see cref="QueryConfigHandler"/> it will listen too</param> public NumericFieldConfigListener(QueryConfigHandler config) { if (config == null) { throw new ArgumentException("config cannot be null!"); } this.config = config; }
/// <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> /// <see cref="StandardQueryNodeProcessorPipeline.StandardQueryNodeProcessorPipeline(QueryConfigHandler)"/> /// </summary> public PrecedenceQueryNodeProcessorPipeline(QueryConfigHandler queryConfig) : base(queryConfig) { for (int i = 0; i < Count; i++) { if (this[i].GetType().Equals(typeof(BooleanQuery2ModifierNodeProcessor))) { RemoveAt(i--); } } Add(new BooleanModifiersQueryNodeProcessor()); }
public override IQueryNode Process(IQueryNode queryTree) { QueryConfigHandler queryConfig = GetQueryConfigHandler(); if (queryConfig != null) { if (queryConfig.TryGetValue(ConfigurationKeys.PHRASE_SLOP, out int defaultPhraseSlop)) { this.defaultPhraseSlop = defaultPhraseSlop; return(base.Process(queryTree)); } } return(queryTree); }
public override IQueryNode Process(IQueryNode queryTree) { QueryConfigHandler queryConfig = GetQueryConfigHandler(); if (queryConfig != null) { int?defaultPhraseSlop = queryConfig.Get(ConfigurationKeys.PHRASE_SLOP); if (defaultPhraseSlop != null) { this.defaultPhraseSlop = defaultPhraseSlop.Value; return(base.Process(queryTree)); } } return(queryTree); }
public QueryNodeProcessor(QueryConfigHandler queryConfigHandler) { this.queryConfig = queryConfigHandler; }
private readonly QueryConfigHandler config = null; // LUCENENET: marked readonly public FieldDateResolutionFCListener(QueryConfigHandler config) { this.config = config; }
public virtual void SetQueryConfigHandler(QueryConfigHandler queryConfigHandler) { this.queryConfig = queryConfigHandler; }
protected QueryNodeProcessor(QueryConfigHandler queryConfigHandler) // LUCENENET: CA1012: Abstract types should not have constructors (marked protected) { this.queryConfig = queryConfigHandler; }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is FieldQueryNode && !(node.Parent is IRangeQueryNode)) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { FieldQueryNode fieldNode = (FieldQueryNode)node; FieldConfig fieldConfig = config.GetFieldConfig(fieldNode .GetFieldAsString()); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { NumberFormat numberFormat = numericConfig.NumberFormat; string text = fieldNode.GetTextAsString(); /*Number*/ object number = null; if (text.Length > 0) { try { number = numberFormat.Parse(text); } catch (FormatException e) { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } switch (numericConfig.Type) { case FieldType.NumericType.LONG: number = Convert.ToInt64(number); break; case FieldType.NumericType.INT: number = Convert.ToInt32(number); break; case FieldType.NumericType.DOUBLE: number = Convert.ToDouble(number); break; case FieldType.NumericType.FLOAT: number = Convert.ToSingle(number); break; } } else { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.GetFieldAsString())); } NumericQueryNode lowerNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); NumericQueryNode upperNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); return(new NumericRangeQueryNode(lowerNode, upperNode, true, true, numericConfig)); } } } } return(node); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is TermRangeQueryNode) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { TermRangeQueryNode termRangeNode = (TermRangeQueryNode)node; FieldConfig fieldConfig = config.GetFieldConfig(StringUtils .ToString(termRangeNode.Field)); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { FieldQueryNode lower = (FieldQueryNode)termRangeNode.LowerBound; FieldQueryNode upper = (FieldQueryNode)termRangeNode.UpperBound; string lowerText = lower.GetTextAsString(); string upperText = upper.GetTextAsString(); NumberFormat numberFormat = numericConfig.NumberFormat; /*Number*/ object lowerNumber = null, upperNumber = null; if (lowerText.Length > 0) { try { lowerNumber = numberFormat.Parse(lowerText); } catch (FormatException e) { throw new QueryNodeParseException(new Message( QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower .GetTextAsString(), numberFormat.ToString()), e); } } if (upperText.Length > 0) { try { upperNumber = numberFormat.Parse(upperText); } catch (FormatException e) { throw new QueryNodeParseException(new Message( QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper .GetTextAsString(), numberFormat.ToString()), e); } } switch (numericConfig.Type) { case NumericType.INT64: if (upperNumber != null) { upperNumber = Convert.ToInt64(upperNumber); // LUCENENET TODO: Find a way to pass culture } if (lowerNumber != null) { lowerNumber = Convert.ToInt64(lowerNumber); } break; case NumericType.INT32: if (upperNumber != null) { upperNumber = Convert.ToInt32(upperNumber); // LUCENENET TODO: Find a way to pass culture } if (lowerNumber != null) { lowerNumber = Convert.ToInt32(lowerNumber); } break; case NumericType.DOUBLE: if (upperNumber != null) { upperNumber = Convert.ToDouble(upperNumber); // LUCENENET TODO: Find a way to pass culture } if (lowerNumber != null) { lowerNumber = Convert.ToDouble(lowerNumber); } break; case NumericType.SINGLE: if (upperNumber != null) { upperNumber = Convert.ToSingle(upperNumber); // LUCENENET TODO: Find a way to pass culture } if (lowerNumber != null) { lowerNumber = Convert.ToSingle(lowerNumber); } break; } NumericQueryNode lowerNode = new NumericQueryNode( termRangeNode.Field, lowerNumber, numberFormat); NumericQueryNode upperNode = new NumericQueryNode( termRangeNode.Field, upperNumber, numberFormat); bool lowerInclusive = termRangeNode.IsLowerInclusive; bool upperInclusive = termRangeNode.IsUpperInclusive; return(new NumericRangeQueryNode(lowerNode, upperNode, lowerInclusive, upperInclusive, numericConfig)); } } } } return(node); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is FieldQueryNode fieldNode && !(node.Parent is IRangeQueryNode)) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { FieldConfig fieldConfig = config.GetFieldConfig(fieldNode .GetFieldAsString()); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { NumberFormat numberFormat = numericConfig.NumberFormat; string text = fieldNode.GetTextAsString(); Number number; // LUCENENET: IDE0059: Remove unnecessary value assignment if (text.Length > 0) { try { number = numberFormat.Parse(text); } catch (FormatException e) // LUCENENET: In .NET we are expecting the framework to throw FormatException, not ParseException { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } switch (numericConfig.Type) { case NumericType.INT64: number = J2N.Numerics.Int64.GetInstance(number.ToInt64()); break; case NumericType.INT32: number = J2N.Numerics.Int32.GetInstance(number.ToInt32()); break; case NumericType.DOUBLE: number = J2N.Numerics.Double.GetInstance(number.ToDouble()); break; case NumericType.SINGLE: number = J2N.Numerics.Single.GetInstance(number.ToSingle()); break; } } else { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.GetFieldAsString())); } NumericQueryNode lowerNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); NumericQueryNode upperNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); return(new NumericRangeQueryNode(lowerNode, upperNode, true, true, numericConfig)); } } } } return(node); }
/// <summary> /// Returns the fields used to expand the query when the field for a /// certain query is <c>null</c> /// </summary> /// <returns>the fields used to expand the query</returns> public virtual string[] GetMultiFields() { return(QueryConfigHandler.Get(ConfigurationKeys.MULTI_FIELDS)); }
public virtual void SetDefaultPhraseSlop(int defaultPhraseSlop) { QueryConfigHandler.Set(ConfigurationKeys.PHRASE_SLOP, defaultPhraseSlop); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is TermRangeQueryNode termRangeNode) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { FieldConfig fieldConfig = config.GetFieldConfig(StringUtils .ToString(termRangeNode.Field)); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { FieldQueryNode lower = (FieldQueryNode)termRangeNode.LowerBound; FieldQueryNode upper = (FieldQueryNode)termRangeNode.UpperBound; string lowerText = lower.GetTextAsString(); string upperText = upper.GetTextAsString(); NumberFormat numberFormat = numericConfig.NumberFormat; J2N.Numerics.Number lowerNumber = null, upperNumber = null; if (lowerText.Length > 0) { try { lowerNumber = numberFormat.Parse(lowerText); } catch (FormatException e) // LUCENENET: In .NET we are expecting the framework to throw FormatException, not ParseException { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower .GetTextAsString(), numberFormat.ToString()), e); } } if (upperText.Length > 0) { try { upperNumber = numberFormat.Parse(upperText); } catch (FormatException e) // LUCENENET: In .NET we are expecting the framework to throw FormatException, not ParseException { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper .GetTextAsString(), numberFormat.ToString()), e); } } switch (numericConfig.Type) { case NumericType.INT64: if (upperNumber != null) { upperNumber = J2N.Numerics.Int64.GetInstance(upperNumber.ToInt64()); } if (lowerNumber != null) { lowerNumber = J2N.Numerics.Int64.GetInstance(lowerNumber.ToInt64()); } break; case NumericType.INT32: if (upperNumber != null) { upperNumber = J2N.Numerics.Int32.GetInstance(upperNumber.ToInt32()); } if (lowerNumber != null) { lowerNumber = J2N.Numerics.Int32.GetInstance(lowerNumber.ToInt32()); } break; case NumericType.DOUBLE: if (upperNumber != null) { upperNumber = J2N.Numerics.Double.GetInstance(upperNumber.ToDouble()); } if (lowerNumber != null) { lowerNumber = J2N.Numerics.Double.GetInstance(lowerNumber.ToDouble()); } break; case NumericType.SINGLE: if (upperNumber != null) { upperNumber = J2N.Numerics.Single.GetInstance(upperNumber.ToSingle()); } if (lowerNumber != null) { lowerNumber = J2N.Numerics.Single.GetInstance(lowerNumber.ToSingle()); } break; } NumericQueryNode lowerNode = new NumericQueryNode( termRangeNode.Field, lowerNumber, numberFormat); NumericQueryNode upperNode = new NumericQueryNode( termRangeNode.Field, upperNumber, numberFormat); bool lowerInclusive = termRangeNode.IsLowerInclusive; bool upperInclusive = termRangeNode.IsUpperInclusive; return(new NumericRangeQueryNode(lowerNode, upperNode, lowerInclusive, upperInclusive, numericConfig)); } } } } return(node); }
public FieldBoostMapFCListener(QueryConfigHandler config) { this.config = config; }
/// <summary> /// Constructs a <see cref="NumericFieldConfigListener"/> object using the given <see cref="QueryConfigHandler"/>. /// </summary> /// <param name="config">the <see cref="QueryConfigHandler"/> it will listen too</param> public NumericFieldConfigListener(QueryConfigHandler config) { this.config = config ?? throw new ArgumentNullException(nameof(config), "config cannot be null!"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) }
/// <summary> /// Constructs a <see cref="NumericFieldConfigListener"/> object using the given <see cref="QueryConfigHandler"/>. /// </summary> /// <param name="config">the <see cref="QueryConfigHandler"/> it will listen too</param> public NumericFieldConfigListener(QueryConfigHandler config) { this.config = config ?? throw new ArgumentNullException(nameof(config), "config cannot be null!"); }
/// <summary> /// Sets the default <see cref="DateTools.Resolution"/> used for certain field when /// no <see cref="DateTools.Resolution"/> is defined for this field. /// </summary> /// <param name="dateResolution">the default <see cref="DateTools.Resolution"/></param> // LUCENENET NOTE: This method is required by the ICommonQueryParserConfiguration interface public virtual void SetDateResolution(DateTools.Resolution dateResolution) { QueryConfigHandler.Set(ConfigurationKeys.DATE_RESOLUTION, dateResolution); }