/// <summary> /// Merges in the stored fields from the readers in /// <code>mergeState</code>. The default implementation skips /// over deleted documents, and uses <seealso cref="#startDocument(int)"/>, /// <seealso cref="#writeField(FieldInfo, IndexableField)"/>, and <seealso cref="#finish(FieldInfos, int)"/>, /// returning the number of documents that were written. /// Implementations can override this method for more sophisticated /// merging (bulk-byte copying, etc). /// </summary> public virtual int Merge(MergeState mergeState) { int docCount = 0; foreach (AtomicReader reader in mergeState.Readers) { int maxDoc = reader.MaxDoc; Bits liveDocs = reader.LiveDocs; for (int i = 0; i < maxDoc; i++) { if (liveDocs != null && !liveDocs.Get(i)) { // skip deleted docs continue; } // TODO: this could be more efficient using // FieldVisitor instead of loading/writing entire // doc; ie we just have to renumber the field number // on the fly? // NOTE: it's very important to first assign to doc then pass it to // fieldsWriter.addDocument; see LUCENE-1282 Document doc = reader.Document(i); AddDocument(doc, mergeState.FieldInfos); docCount++; mergeState.checkAbort.Work(300); } } Finish(mergeState.FieldInfos, docCount); return(docCount); }
public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs) { FixedBitSet bits = new FixedBitSet(context.Reader.MaxDoc); bits.Set(Doc); if (acceptDocs != null && !acceptDocs.Get(Doc)) { bits.Clear(Doc); } return bits; }
public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs) { FixedBitSet bits = new FixedBitSet(context.Reader.MaxDoc); bits.Set(Doc); if (acceptDocs != null && !acceptDocs.Get(Doc)) { bits.Clear(Doc); } return(bits); }
public static void PrintDelDocs(Bits bits) { if (bits == null) { return; } for (int x = 0; x < bits.Length(); x++) { Console.WriteLine(x + ":" + bits.Get(x)); } }
protected override bool Match(int docid) { return(AcceptDocs.Get(docid)); }
private static void CheckSortedSetDocValues(string fieldName, AtomicReader reader, SortedSetDocValues dv, Bits docsWithField) { long maxOrd = dv.ValueCount - 1; LongBitSet seenOrds = new LongBitSet(dv.ValueCount); long maxOrd2 = -1; for (int i = 0; i < reader.MaxDoc; i++) { dv.Document = i; long lastOrd = -1; long ord; if (docsWithField.Get(i)) { int ordCount = 0; while ((ord = dv.NextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { if (ord <= lastOrd) { throw new Exception("ords out of order: " + ord + " <= " + lastOrd + " for doc: " + i); } if (ord < 0 || ord > maxOrd) { throw new Exception("ord out of bounds: " + ord); } if (dv is RandomAccessOrds) { long ord2 = ((RandomAccessOrds)dv).OrdAt(ordCount); if (ord != ord2) { throw new Exception("ordAt(" + ordCount + ") inconsistent, expected=" + ord + ",got=" + ord2 + " for doc: " + i); } } lastOrd = ord; maxOrd2 = Math.Max(maxOrd2, ord); seenOrds.Set(ord); ordCount++; } if (ordCount == 0) { throw new Exception("dv for field: " + fieldName + " has no ordinals but is not marked missing for doc: " + i); } if (dv is RandomAccessOrds) { long ordCount2 = ((RandomAccessOrds)dv).Cardinality(); if (ordCount != ordCount2) { throw new Exception("cardinality inconsistent, expected=" + ordCount + ",got=" + ordCount2 + " for doc: " + i); } } } else { long o = dv.NextOrd(); if (o != SortedSetDocValues.NO_MORE_ORDS) { throw new Exception("dv for field: " + fieldName + " is marked missing but has ord=" + o + " for doc: " + i); } if (dv is RandomAccessOrds) { long ordCount2 = ((RandomAccessOrds)dv).Cardinality(); if (ordCount2 != 0) { throw new Exception("dv for field: " + fieldName + " is marked missing but has cardinality " + ordCount2 + " for doc: " + i); } } } } if (maxOrd != maxOrd2) { throw new Exception("dv for field: " + fieldName + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2); } if (seenOrds.Cardinality() != dv.ValueCount) { throw new Exception("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality()); } BytesRef lastValue = null; BytesRef scratch = new BytesRef(); for (long i = 0; i <= maxOrd; i++) { dv.LookupOrd(i, scratch); Debug.Assert(scratch.Valid); if (lastValue != null) { if (scratch.CompareTo(lastValue) <= 0) { throw new Exception("dv for field: " + fieldName + " has ords out of order: " + lastValue + " >=" + scratch); } } lastValue = BytesRef.DeepCopyOf(scratch); } }
private static void CheckSortedDocValues(string fieldName, AtomicReader reader, SortedDocValues dv, Bits docsWithField) { CheckBinaryDocValues(fieldName, reader, dv, docsWithField); int maxOrd = dv.ValueCount - 1; FixedBitSet seenOrds = new FixedBitSet(dv.ValueCount); int maxOrd2 = -1; for (int i = 0; i < reader.MaxDoc; i++) { int ord = dv.GetOrd(i); if (ord == -1) { if (docsWithField.Get(i)) { throw new Exception("dv for field: " + fieldName + " has -1 ord but is not marked missing for doc: " + i); } } else if (ord < -1 || ord > maxOrd) { throw new Exception("ord out of bounds: " + ord); } else { if (!docsWithField.Get(i)) { throw new Exception("dv for field: " + fieldName + " is missing but has ord=" + ord + " for doc: " + i); } maxOrd2 = Math.Max(maxOrd2, ord); seenOrds.Set(ord); } } if (maxOrd != maxOrd2) { throw new Exception("dv for field: " + fieldName + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2); } if (seenOrds.Cardinality() != dv.ValueCount) { throw new Exception("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.ValueCount + " but only used: " + seenOrds.Cardinality()); } BytesRef lastValue = null; BytesRef scratch = new BytesRef(); for (int i = 0; i <= maxOrd; i++) { dv.LookupOrd(i, scratch); Debug.Assert(scratch.Valid); if (lastValue != null) { if (scratch.CompareTo(lastValue) <= 0) { throw new Exception("dv for field: " + fieldName + " has ords out of order: " + lastValue + " >=" + scratch); } } lastValue = BytesRef.DeepCopyOf(scratch); } }
private static void CheckNumericDocValues(string fieldName, AtomicReader reader, NumericDocValues ndv, Bits docsWithField) { for (int i = 0; i < reader.MaxDoc; i++) { long value = ndv.Get(i); if (docsWithField.Get(i) == false && value != 0) { throw new Exception("dv for field: " + fieldName + " is marked missing but has value=" + value + " for doc: " + i); } } }
private static void CheckBinaryDocValues(string fieldName, AtomicReader reader, BinaryDocValues dv, Bits docsWithField) { BytesRef scratch = new BytesRef(); for (int i = 0; i < reader.MaxDoc; i++) { dv.Get(i, scratch); Debug.Assert(scratch.Valid); if (docsWithField.Get(i) == false && scratch.Length > 0) { throw new Exception("dv for field: " + fieldName + " is missing but has value=" + scratch + " for doc: " + i); } } }
protected internal override sealed bool MatchDoc(int doc) { return(DocsWithField.Get(doc)); }
public virtual bool Get(int docid) { return(Bits.Get(docid) && OuterInstance.Match(docid)); }
private void AssertEquals(Bits expected, Bits actual) { Assert.AreEqual(expected.Length(), actual.Length()); for (int i = 0; i < expected.Length(); i++) { Assert.AreEqual(expected.Get(i), actual.Get(i)); } }
public static DocMap Build(int maxDoc, Bits liveDocs) { Debug.Assert(liveDocs != null); MonotonicAppendingLongBuffer docMap = new MonotonicAppendingLongBuffer(); int del = 0; for (int i = 0; i < maxDoc; ++i) { docMap.Add(i - del); if (!liveDocs.Get(i)) { ++del; } } docMap.Freeze(); int numDeletedDocs = del; Debug.Assert(docMap.Size() == maxDoc); return new DocMapAnonymousInnerClassHelper(maxDoc, liveDocs, docMap, numDeletedDocs); }