예제 #1
0
        internal ExpressionValueSource(Bindings bindings, Expression expression)
        {
            if (bindings == null)
            {
                throw new ArgumentNullException();
            }
            if (expression == null)
            {
                throw new ArgumentNullException();
            }
            this.expression = expression;
            variables       = new ValueSource[expression.Variables.Length];
            bool needsScores = false;

            for (int i = 0; i < variables.Length; i++)
            {
                ValueSource source = bindings.GetValueSource(expression.Variables[i]);
                if (source is ScoreValueSource)
                {
                    needsScores = true;
                }
                else
                {
                    var valueSource = source as ExpressionValueSource;
                    if (valueSource != null)
                    {
                        if (valueSource.NeedsScores)
                        {
                            needsScores = true;
                        }
                    }
                    else
                    {
                        if (source == null)
                        {
                            throw new InvalidOperationException("Internal error. Variable (" + expression.Variables[i]
                                                                + ") does not exist.");
                        }
                    }
                }
                variables[i] = source;
            }
            this.needsScores = needsScores;
        }
예제 #2
0
		internal ExpressionValueSource(Bindings bindings, Expression expression)
		{
			if (bindings == null)
			{
				throw new ArgumentNullException();
			}
			if (expression == null)
			{
				throw new ArgumentNullException();
			}
			this.expression = expression;
			variables = new ValueSource[expression.variables.Length];
			bool needsScores = false;
			for (int i = 0; i < variables.Length; i++)
			{
				ValueSource source = bindings.GetValueSource(expression.variables[i]);
				if (source is ScoreValueSource)
				{
					needsScores = true;
				}
				else
				{
				    var valueSource = source as ExpressionValueSource;
				    if (valueSource != null)
					{
						if (valueSource.NeedsScores())
						{
							needsScores = true;
						}
					}
					else
					{
						if (source == null)
						{
							throw new SystemException("Internal error. Variable (" + expression.variables[i]
								 + ") does not exist.");
						}
					}
				}
			    variables[i] = source;
			}
			this.needsScores = needsScores;
		}
예제 #3
0
        internal ExpressionValueSource(Bindings bindings, Expression expression)
        {
            if (bindings is null)
            {
                throw new ArgumentNullException(nameof(bindings)); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention)
            }

            this.expression = expression ?? throw new ArgumentNullException(nameof(expression)); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention)
            variables       = new ValueSource[expression.Variables.Length];
            bool needsScores = false;

            for (int i = 0; i < variables.Length; i++)
            {
                ValueSource source = bindings.GetValueSource(expression.Variables[i]);
                if (source is ScoreValueSource)
                {
                    needsScores = true;
                }
                else
                {
                    if (source is ExpressionValueSource valueSource)
                    {
                        if (valueSource.NeedsScores)
                        {
                            needsScores = true;
                        }
                    }
                    else
                    {
                        if (source == null)
                        {
                            // LUCENENET specific: Changed from RuntimeException to InvalidOperationException to match .NET conventions
                            throw IllegalStateException.Create("Internal error. Variable (" + expression.Variables[i]
                                                               + ") does not exist.");
                        }
                    }
                }
                variables[i] = source;
            }
            this.needsScores = needsScores;
        }
예제 #4
0
        public override Explanation Explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID)
        {
            Explanation result = base.Explain(searcher, firstPassExplanation, docID);
            IList <AtomicReaderContext> leaves = searcher.IndexReader.Leaves;
            int subReader = ReaderUtil.SubIndex(docID, leaves);
            AtomicReaderContext readerContext = leaves[subReader];
            int docIDInSegment = docID - readerContext.DocBase;
            var context        = new Dictionary <string, object>();
            var fakeScorer     = new FakeScorer {
                score = firstPassExplanation.Value, doc = docIDInSegment
            };

            context["scorer"] = fakeScorer;
            foreach (string variable in expression.variables)
            {
                result.AddDetail(new Explanation((float)bindings.GetValueSource(variable).GetValues
                                                     (context, readerContext).DoubleVal(docIDInSegment), "variable \"" + variable + "\""
                                                 ));
            }
            return(result);
        }