Ejemplo n.º 1
0
        public virtual void TestTypes()
        {
            Expression     expr     = JavascriptCompiler.Compile("2*popularity");
            SimpleBindings bindings = new SimpleBindings();

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

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

            AreEqual(10, values.DoubleVal(0), 0);
            AreEqual(10, values.FloatVal(0), 0);
            AreEqual(10, values.LongVal(0));
            AreEqual(10, values.IntVal(0));
            AreEqual(10, values.ShortVal(0));
            AreEqual(10, values.ByteVal(0));
            AreEqual("10", values.StrVal(0));
            AreEqual(System.Convert.ToDouble(10), values.ObjectVal(0));
            AreEqual(40, values.DoubleVal(1), 0);
            AreEqual(40, values.FloatVal(1), 0);
            AreEqual(40, values.LongVal(1));
            AreEqual(40, values.IntVal(1));
            AreEqual(40, values.ShortVal(1));
            AreEqual(40, values.ByteVal(1));
            AreEqual("40", values.StrVal(1));
            AreEqual(System.Convert.ToDouble(40), values.ObjectVal(1));
            AreEqual(4, values.DoubleVal(2), 0);
            AreEqual(4, values.FloatVal(2), 0);
            AreEqual(4, values.LongVal(2));
            AreEqual(4, values.IntVal(2));
            AreEqual(4, values.ShortVal(2));
            AreEqual(4, values.ByteVal(2));
            AreEqual("4", values.StrVal(2));
            AreEqual(System.Convert.ToDouble(4), values.ObjectVal(2));
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Returns the weight for the current <code>docId</code> as computed
            /// by the <code>weightsValueSource</code>
            ///
            /// </summary>
            protected internal override long GetWeight(Document doc, int docId)
            {
                if (currentWeightValues == null)
                {
                    return(0);
                }
                int subIndex = ReaderUtil.subIndex(docId, starts);

                if (subIndex != currentLeafIndex)
                {
                    currentLeafIndex = subIndex;
                    try
                    {
                        currentWeightValues = outerInstance.weightsValueSource.GetValues(new Dictionary <string, object>(), leaves[currentLeafIndex]);
                    }
                    catch (IOException)
                    {
                        throw new Exception();
                    }
                }
                return(currentWeightValues.LongVal(docId - starts[subIndex]));
            }
Ejemplo n.º 3
0
 public override long LongVal(int doc)
 {
     return(ifVals.BoolVal(doc) ? trueVals.LongVal(doc) : falseVals.LongVal(doc));
 }
Ejemplo n.º 4
0
 public override void LongVal(int doc, long[] vals)
 {
     vals[0] = x.LongVal(doc);
     vals[1] = y.LongVal(doc);
 }
Ejemplo n.º 5
0
        private void Count(ValueSource valueSource, IList <MatchingDocs> matchingDocs)
        {
            LongRange[] ranges = (LongRange[])this.Ranges;

            LongRangeCounter counter = new LongRangeCounter(ranges);

            int missingCount = 0;

            foreach (MatchingDocs hits in matchingDocs)
            {
                FunctionValues fv = valueSource.GetValues(new Dictionary <string, object>(), hits.context);

                TotCount += hits.totalHits;
                Bits bits;
                if (FastMatchFilter != null)
                {
                    DocIdSet dis = FastMatchFilter.GetDocIdSet(hits.context, null);
                    if (dis == null)
                    {
                        // No documents match
                        continue;
                    }
                    bits = dis.GetBits();
                    if (bits == null)
                    {
                        throw new System.ArgumentException("fastMatchFilter does not implement DocIdSet.bits");
                    }
                }
                else
                {
                    bits = null;
                }

                DocIdSetIterator docs = hits.bits.GetIterator();
                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    if (bits != null && bits.Get(doc) == false)
                    {
                        doc++;
                        continue;
                    }
                    // Skip missing docs:
                    if (fv.Exists(doc))
                    {
                        counter.add(fv.LongVal(doc));
                    }
                    else
                    {
                        missingCount++;
                    }
                }
            }

            int x = counter.fillCounts(Counts);

            missingCount += x;

            //System.out.println("totCount " + totCount + " missingCount " + counter.missingCount);
            TotCount -= missingCount;
        }
Ejemplo n.º 6
0
        private void DoTest(FieldInfo.DocValuesType_e type)
        {
            Directory         d        = NewDirectory();
            IndexWriterConfig iwConfig = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            int   nDocs = AtLeast(50);
            Field id    = new NumericDocValuesField("id", 0);
            Field f;

            switch (type)
            {
            case FieldInfo.DocValuesType_e.BINARY:
                f = new BinaryDocValuesField("dv", new BytesRef());
                break;

            case FieldInfo.DocValuesType_e.SORTED:
                f = new SortedDocValuesField("dv", new BytesRef());
                break;

            case FieldInfo.DocValuesType_e.NUMERIC:
                f = new NumericDocValuesField("dv", 0);
                break;

            default:
                throw new InvalidOperationException();
            }
            Document document = new Document();

            document.Add(id);
            document.Add(f);

            object[] vals = new object[nDocs];

            RandomIndexWriter iw = new RandomIndexWriter(Random(), d, iwConfig);

            for (int i = 0; i < nDocs; ++i)
            {
                id.LongValue = i;
                switch (type)
                {
                case FieldInfo.DocValuesType_e.SORTED:
                case FieldInfo.DocValuesType_e.BINARY:
                    do
                    {
                        vals[i] = TestUtil.RandomSimpleString(Random(), 20);
                    } while (((string)vals[i]).Length == 0);
                    f.BytesValue = new BytesRef((string)vals[i]);
                    break;

                case FieldInfo.DocValuesType_e.NUMERIC:
                    int bitsPerValue = Random().NextIntBetween(1, 31);     // keep it an int
                    vals[i]     = (long)Random().Next((int)PackedInts.MaxValue(bitsPerValue));
                    f.LongValue = (long)vals[i];
                    break;
                }
                iw.AddDocument(document);
                if (Random().NextBoolean() && i % 10 == 9)
                {
                    iw.Commit();
                }
            }
            iw.Dispose();

            DirectoryReader rd = DirectoryReader.Open(d);

            foreach (AtomicReaderContext leave in rd.Leaves)
            {
                FunctionValues ids = (new LongFieldSource("id")).GetValues(null, leave);
                ValueSource    vs;
                switch (type)
                {
                case FieldInfo.DocValuesType_e.BINARY:
                case FieldInfo.DocValuesType_e.SORTED:
                    vs = new BytesRefFieldSource("dv");
                    break;

                case FieldInfo.DocValuesType_e.NUMERIC:
                    vs = new LongFieldSource("dv");
                    break;

                default:
                    throw new InvalidOperationException();
                }
                FunctionValues values = vs.GetValues(null, leave);
                BytesRef       bytes  = new BytesRef();
                for (int i = 0; i < leave.AtomicReader.MaxDoc; ++i)
                {
                    assertTrue(values.Exists(i));
                    if (vs is BytesRefFieldSource)
                    {
                        assertTrue(values.ObjectVal(i) is string);
                    }
                    else if (vs is LongFieldSource)
                    {
                        assertTrue(values.ObjectVal(i) is long?);
                        assertTrue(values.BytesVal(i, bytes));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }

                    object expected = vals[ids.IntVal(i)];
                    switch (type)
                    {
                    case FieldInfo.DocValuesType_e.SORTED:
                        values.OrdVal(i);     // no exception
                        assertTrue(values.NumOrd() >= 1);
                        goto case FieldInfo.DocValuesType_e.BINARY;

                    case FieldInfo.DocValuesType_e.BINARY:
                        assertEquals(expected, values.ObjectVal(i));
                        assertEquals(expected, values.StrVal(i));
                        assertEquals(expected, values.ObjectVal(i));
                        assertEquals(expected, values.StrVal(i));
                        assertTrue(values.BytesVal(i, bytes));
                        assertEquals(new BytesRef((string)expected), bytes);
                        break;

                    case FieldInfo.DocValuesType_e.NUMERIC:
                        assertEquals(Number.ToInt64(expected.ToString()), values.LongVal(i));
                        break;
                    }
                }
            }
            rd.Dispose();
            d.Dispose();
        }