예제 #1
0
        public virtual void TestRangeScorer()
        {
            Expression     expr     = JavascriptCompiler.Compile("2*popularity");
            SimpleBindings bindings = new SimpleBindings();

            bindings.Add(new SortField("popularity", SortFieldType.INT64));
            ValueSource vs = expr.GetValueSource(bindings);

            Assert.AreEqual(1, reader.Leaves.Count);
            AtomicReaderContext leaf   = reader.Leaves[0];
            FunctionValues      values = vs.GetValues(new Dictionary <string, object>(), leaf);
            // everything
            ValueSourceScorer scorer = values.GetRangeScorer(leaf.Reader, "4"
                                                             , "40", true, true);

            Assert.AreEqual(-1, scorer.DocID);
            Assert.AreEqual(0, scorer.NextDoc());
            Assert.AreEqual(1, scorer.NextDoc());
            Assert.AreEqual(2, scorer.NextDoc());
            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, scorer.NextDoc());
            // just the first doc
            scorer = values.GetRangeScorer(leaf.Reader, "4", "40", false, false);
            Assert.AreEqual(-1, scorer.DocID);
            Assert.AreEqual(0, scorer.NextDoc());
            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, scorer.NextDoc());
        }
예제 #2
0
        public virtual void TestEquals()
        {
            Expression expr = JavascriptCompiler.Compile("sqrt(a) + ln(b)");

            SimpleBindings bindings = new SimpleBindings();

            bindings.Add(new SortField("a", SortFieldType.INT32));
            bindings.Add(new SortField("b", SortFieldType.INT32));

            ValueSource vs1 = expr.GetValueSource(bindings);

            // same instance
            Assert.AreEqual(vs1, vs1);
            // null
            Assert.IsFalse(vs1.Equals(null));
            // other object
            Assert.IsFalse(vs1.Equals("foobar"));

            // same bindings and expression instances
            ValueSource vs2 = expr.GetValueSource(bindings);

            Assert.AreEqual(vs1.GetHashCode(), vs2.GetHashCode());
            Assert.AreEqual(vs1, vs2);

            // equiv bindings (different instance)
            SimpleBindings bindings2 = new SimpleBindings();

            bindings2.Add(new SortField("a", SortFieldType.INT32));
            bindings2.Add(new SortField("b", SortFieldType.INT32));
            ValueSource vs3 = expr.GetValueSource(bindings2);

            Assert.AreEqual(vs1, vs3);

            // different bindings (same names, different types)
            SimpleBindings bindings3 = new SimpleBindings();

            bindings3.Add(new SortField("a", SortFieldType.INT64));
            bindings3.Add(new SortField("b", SortFieldType.INT32));
            ValueSource vs4 = expr.GetValueSource(bindings3);

            Assert.IsFalse(vs1.Equals(vs4));
        }
예제 #3
0
        /// <summary>Traverses the graph of bindings, checking there are no cycles or missing references</summary>
        /// <exception cref="System.ArgumentException">if the bindings is inconsistent</exception>
        public void Validate()
        {
            foreach (object o in map.Values)
            {
                if (o is Expression)
                {
                    Expression expr = (Expression)o;

                    expr.GetValueSource(this);
                }
            }
        }
예제 #4
0
 /// <summary>Traverses the graph of bindings, checking there are no cycles or missing references
 ///     </summary>
 /// <exception cref="System.ArgumentException">if the bindings is inconsistent</exception>
 public void Validate()
 {
     foreach (object o in map.Values)
     {
         if (o is Expression)
         {
             Expression expr = (Expression)o;
             try
             {
                 expr.GetValueSource(this);
             }
             catch (StackOverflowException)
             {
                 throw new ArgumentException("Recursion Error: Cycle detected originating in (" + expr.sourceText + ")");
             }
         }
     }
 }
예제 #5
0
        public virtual void TestTypes()
        {
            Expression     expr     = JavascriptCompiler.Compile("2*popularity");
            SimpleBindings bindings = new SimpleBindings();

            bindings.Add(new SortField("popularity", SortFieldType.INT64));
            ValueSource vs = expr.GetValueSource(bindings);

            Assert.AreEqual(1, reader.Leaves.Count);
            AtomicReaderContext leaf   = reader.Leaves[0];
            FunctionValues      values = vs.GetValues(new Dictionary <string, object>(), leaf);

            Assert.AreEqual(10, values.DoubleVal(0), 0);
            Assert.AreEqual(10, values.SingleVal(0), 0);
            Assert.AreEqual(10, values.Int64Val(0));
            Assert.AreEqual(10, values.Int32Val(0));
            Assert.AreEqual(10, values.Int16Val(0));
            Assert.AreEqual((byte)10, values.ByteVal(0));
            Assert.AreEqual("10.0", values.StrVal(0));
            Assert.AreEqual(J2N.Numerics.Double.GetInstance(10), values.ObjectVal(0));

            Assert.AreEqual(40, values.DoubleVal(1), 0);
            Assert.AreEqual(40, values.SingleVal(1), 0);
            Assert.AreEqual(40, values.Int64Val(1));
            Assert.AreEqual(40, values.Int32Val(1));
            Assert.AreEqual(40, values.Int16Val(1));
            Assert.AreEqual((byte)40, values.ByteVal(1));
            Assert.AreEqual("40.0", values.StrVal(1));
            Assert.AreEqual(J2N.Numerics.Double.GetInstance(40), values.ObjectVal(1));

            Assert.AreEqual(4, values.DoubleVal(2), 0);
            Assert.AreEqual(4, values.SingleVal(2), 0);
            Assert.AreEqual(4, values.Int64Val(2));
            Assert.AreEqual(4, values.Int32Val(2));
            Assert.AreEqual(4, values.Int16Val(2));
            Assert.AreEqual((byte)4, values.ByteVal(2));
            Assert.AreEqual("4.0", values.StrVal(2));
            Assert.AreEqual(J2N.Numerics.Double.GetInstance(4), values.ObjectVal(2));
        }