示例#1
0
            internal SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher)
                : base(weight)
            {
                this.Dv     = reader.GetSortedSetDocValues("dv");
                this.MaxDoc = reader.MaxDoc;
                BooleanQuery bq = (BooleanQuery)weight.Query;

                this.MinNrShouldMatch = bq.MinimumNumberShouldMatch;
                this.Sims             = new SimScorer[(int)Dv.ValueCount];
                foreach (BooleanClause clause in bq.Clauses)
                {
                    Debug.Assert(!clause.Prohibited);
                    Debug.Assert(!clause.Required);
                    Term term = ((TermQuery)clause.Query).Term;
                    long ord  = Dv.LookupTerm(term.Bytes);
                    if (ord >= 0)
                    {
                        bool success = Ords.Add(ord);
                        Debug.Assert(success); // no dups
                        TermContext context = TermContext.Build(reader.Context, term);
                        SimWeight   w       = weight.Similarity.ComputeWeight(1f, searcher.CollectionStatistics("field"), searcher.TermStatistics(term, context));
                        var         dummy   = w.ValueForNormalization; // ignored
                        w.Normalize(1F, 1F);
                        Sims[(int)ord] = weight.Similarity.DoSimScorer(w, (AtomicReaderContext)reader.Context);
                    }
                }
            }
示例#2
0
        /// <summary>
        /// Creates this, pulling doc values from the specified
        /// field.
        /// </summary>
        public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = FacetsConfig.DEFAULT_INDEX_FIELD_NAME)
        {
            this.field      = field;
            this.origReader = reader;

            // We need this to create thread-safe MultiSortedSetDV
            // per collector:
            topReader = SlowCompositeReaderWrapper.Wrap(reader);
            SortedSetDocValues dv = topReader.GetSortedSetDocValues(field);

            if (dv is null)
            {
                throw new ArgumentException("field \"" + field + "\" was not indexed with SortedSetDocValues");
            }
            if (dv.ValueCount > int.MaxValue)
            {
                throw new ArgumentException("can only handle valueCount < System.Int32.MaxValue; got " + dv.ValueCount);
            }
            valueCount = (int)dv.ValueCount;

            // TODO: we can make this more efficient if eg we can be
            // "involved" when IOrdinalMap is being created?  Ie see
            // each term/ord it's assigning as it goes...
            string   lastDim  = null;
            int      startOrd = -1;
            BytesRef spare    = new BytesRef();

            // TODO: this approach can work for full hierarchy?;
            // TaxoReader can't do this since ords are not in
            // "sorted order" ... but we should generalize this to
            // support arbitrary hierarchy:
            for (int ord = 0; ord < valueCount; ord++)
            {
                dv.LookupOrd(ord, spare);
                string[] components = FacetsConfig.StringToPath(spare.Utf8ToString());
                if (components.Length != 2)
                {
                    throw new ArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.ToString(components) + " " + spare.Utf8ToString());
                }
                if (!components[0].Equals(lastDim, StringComparison.Ordinal))
                {
                    if (lastDim != null)
                    {
                        prefixToOrdRange[lastDim] = new OrdRange(startOrd, ord - 1);
                    }
                    startOrd = ord;
                    lastDim  = components[0];
                }
            }

            if (lastDim != null)
            {
                prefixToOrdRange[lastDim] = new OrdRange(startOrd, valueCount - 1);
            }
        }
示例#3
0
        public virtual void TestSortedSetDocValuesField()
        {
            AssumeTrue("default codec does not support SORTED_SET", DefaultCodecSupportsSortedSet);
            SortedSetDocValues dv = reader.GetSortedSetDocValues(SORTED_SET_DV_FIELD);
            int      maxDoc       = reader.MaxDoc;
            BytesRef bytes        = new BytesRef();

            for (int i = 0; i < maxDoc; i++)
            {
                dv.SetDocument(i);
                dv.LookupOrd(dv.NextOrd(), bytes);
                int value = sortedValues[i];
                assertEquals("incorrect sorted-set DocValues for doc " + i, value.toString(), bytes.Utf8ToString());
                dv.LookupOrd(dv.NextOrd(), bytes);
                assertEquals("incorrect sorted-set DocValues for doc " + i, (value + 1).ToString(), bytes.Utf8ToString());
                assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.NextOrd());
            }
        }
示例#4
0
 /// <summary>
 /// Return top-level doc values.
 /// </summary>
 public override SortedSetDocValues GetDocValues()
 {
     return(topReader.GetSortedSetDocValues(field));
 }