Exemplo n.º 1
0
 /// <param name="oldFormatImpersonationIsActive">
 /// LUCENENET specific
 /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
 /// </param>
 public Lucene40RWCodec(bool oldFormatImpersonationIsActive)
     : base()
 {
     fieldInfos = new Lucene40FieldInfosFormatAnonymousInnerClassHelper(oldFormatImpersonationIsActive);
     DocValues = new Lucene40RWDocValuesFormat(oldFormatImpersonationIsActive);
     Norms = new Lucene40RWNormsFormat(oldFormatImpersonationIsActive);
 }
Exemplo n.º 2
0
 public Lucene46CodecAnonymousClass(TestPerFieldDocValuesFormat outerInstance, DocValuesFormat fast, DocValuesFormat slow)
 {
     this.outerInstance = outerInstance;
     this.fast          = fast;
     this.slow          = slow;
 }
Exemplo n.º 3
0
        public virtual void WriteFieldUpdates(Directory dir, DocValuesFieldUpdates.Container dvUpdates)
        {
            lock (this)
            {
                //Debug.Assert(Thread.holdsLock(Writer));
                //System.out.println("rld.writeFieldUpdates: seg=" + info + " numericFieldUpdates=" + numericFieldUpdates);

                Debug.Assert(dvUpdates.Any());

                // Do this so we can delete any created files on
                // exception; this saves all codecs from having to do
                // it:
                TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(dir);

                FieldInfos fieldInfos = null;
                bool       success    = false;
                try
                {
                    Codec codec = Info.Info.Codec;

                    // reader could be null e.g. for a just merged segment (from
                    // IndexWriter.commitMergedDeletes).
                    SegmentReader reader = this.reader == null ? new SegmentReader(Info, writer.Config.ReaderTermsIndexDivisor, IOContext.READ_ONCE) : this.reader;
                    try
                    {
                        // clone FieldInfos so that we can update their dvGen separately from
                        // the reader's infos and write them to a new fieldInfos_gen file
                        FieldInfos.Builder builder = new FieldInfos.Builder(writer.globalFieldNumberMap);
                        // cannot use builder.add(reader.getFieldInfos()) because it does not
                        // clone FI.attributes as well FI.dvGen
                        foreach (FieldInfo fi in reader.FieldInfos)
                        {
                            FieldInfo clone = builder.Add(fi);
                            // copy the stuff FieldInfos.Builder doesn't copy
                            if (fi.Attributes != null)
                            {
                                foreach (KeyValuePair <string, string> e in fi.Attributes)
                                {
                                    clone.PutAttribute(e.Key, e.Value);
                                }
                            }
                            clone.DocValuesGen = fi.DocValuesGen;
                        }
                        // create new fields or update existing ones to have NumericDV type
                        foreach (string f in dvUpdates.numericDVUpdates.Keys)
                        {
                            builder.AddOrUpdate(f, NumericDocValuesField.TYPE);
                        }
                        // create new fields or update existing ones to have BinaryDV type
                        foreach (string f in dvUpdates.binaryDVUpdates.Keys)
                        {
                            builder.AddOrUpdate(f, BinaryDocValuesField.fType);
                        }

                        fieldInfos = builder.Finish();
                        long              nextFieldInfosGen     = Info.NextFieldInfosGen;
                        string            segmentSuffix         = nextFieldInfosGen.ToString(CultureInfo.InvariantCulture);//Convert.ToString(nextFieldInfosGen, Character.MAX_RADIX));
                        SegmentWriteState state                 = new SegmentWriteState(null, trackingDir, Info.Info, fieldInfos, writer.Config.TermIndexInterval, null, IOContext.DEFAULT, segmentSuffix);
                        DocValuesFormat   docValuesFormat       = codec.DocValuesFormat;
                        DocValuesConsumer fieldsConsumer        = docValuesFormat.FieldsConsumer(state);
                        bool              fieldsConsumerSuccess = false;
                        try
                        {
                            //          System.out.println("[" + Thread.currentThread().getName() + "] RLD.writeFieldUpdates: applying numeric updates; seg=" + info + " updates=" + numericFieldUpdates);
                            foreach (KeyValuePair <string, NumericDocValuesFieldUpdates> e in dvUpdates.numericDVUpdates)
                            {
                                string field = e.Key;
                                NumericDocValuesFieldUpdates fieldUpdates = e.Value;
                                FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
                                Debug.Assert(fieldInfo != null);

                                fieldInfo.DocValuesGen = nextFieldInfosGen;
                                // write the numeric updates to a new gen'd docvalues file
                                fieldsConsumer.AddNumericField(fieldInfo, GetInt64Enumerable(reader, field, fieldUpdates));
                            }

                            //        System.out.println("[" + Thread.currentThread().getName() + "] RAU.writeFieldUpdates: applying binary updates; seg=" + info + " updates=" + dvUpdates.binaryDVUpdates);
                            foreach (KeyValuePair <string, BinaryDocValuesFieldUpdates> e in dvUpdates.binaryDVUpdates)
                            {
                                string field = e.Key;
                                BinaryDocValuesFieldUpdates dvFieldUpdates = e.Value;
                                FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
                                Debug.Assert(fieldInfo != null);

                                //          System.out.println("[" + Thread.currentThread().getName() + "] RAU.writeFieldUpdates: applying binary updates; seg=" + info + " f=" + dvFieldUpdates + ", updates=" + dvFieldUpdates);

                                fieldInfo.DocValuesGen = nextFieldInfosGen;
                                // write the numeric updates to a new gen'd docvalues file
                                fieldsConsumer.AddBinaryField(fieldInfo, GetBytesRefEnumerable(reader, field, dvFieldUpdates));
                            }

                            codec.FieldInfosFormat.FieldInfosWriter.Write(trackingDir, Info.Info.Name, segmentSuffix, fieldInfos, IOContext.DEFAULT);
                            fieldsConsumerSuccess = true;
                        }
                        finally
                        {
                            if (fieldsConsumerSuccess)
                            {
                                fieldsConsumer.Dispose();
                            }
                            else
                            {
                                IOUtils.DisposeWhileHandlingException(fieldsConsumer);
                            }
                        }
                    }
                    finally
                    {
                        if (reader != this.reader)
                        {
                            //          System.out.println("[" + Thread.currentThread().getName() + "] RLD.writeLiveDocs: closeReader " + reader);
                            reader.Dispose();
                        }
                    }

                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Advance only the nextWriteDocValuesGen so that a 2nd
                        // attempt to write will write to a new file
                        Info.AdvanceNextWriteFieldInfosGen();

                        // Delete any partially created file(s):
                        foreach (string fileName in trackingDir.CreatedFiles)
                        {
                            try
                            {
                                dir.DeleteFile(fileName);
                            }
                            catch (Exception)
                            {
                                // Ignore so we throw only the first exc
                            }
                        }
                    }
                }

                Info.AdvanceFieldInfosGen();
                // copy all the updates to mergingUpdates, so they can later be applied to the merged segment
                if (isMerging)
                {
                    foreach (KeyValuePair <string, NumericDocValuesFieldUpdates> e in dvUpdates.numericDVUpdates)
                    {
                        DocValuesFieldUpdates updates;
                        if (!mergingDVUpdates.TryGetValue(e.Key, out updates))
                        {
                            mergingDVUpdates[e.Key] = e.Value;
                        }
                        else
                        {
                            updates.Merge(e.Value);
                        }
                    }
                    foreach (KeyValuePair <string, BinaryDocValuesFieldUpdates> e in dvUpdates.binaryDVUpdates)
                    {
                        DocValuesFieldUpdates updates;
                        if (!mergingDVUpdates.TryGetValue(e.Key, out updates))
                        {
                            mergingDVUpdates[e.Key] = e.Value;
                        }
                        else
                        {
                            updates.Merge(e.Value);
                        }
                    }
                }

                // create a new map, keeping only the gens that are in use
                IDictionary <long, ISet <string> > genUpdatesFiles    = Info.UpdatesFiles;
                IDictionary <long, ISet <string> > newGenUpdatesFiles = new Dictionary <long, ISet <string> >();
                long fieldInfosGen = Info.FieldInfosGen;
                foreach (FieldInfo fi in fieldInfos)
                {
                    long dvGen = fi.DocValuesGen;
                    if (dvGen != -1 && !newGenUpdatesFiles.ContainsKey(dvGen))
                    {
                        if (dvGen == fieldInfosGen)
                        {
                            newGenUpdatesFiles[fieldInfosGen] = trackingDir.CreatedFiles;
                        }
                        else
                        {
                            newGenUpdatesFiles[dvGen] = genUpdatesFiles[dvGen];
                        }
                    }
                }

                Info.SetGenUpdatesFiles(newGenUpdatesFiles);

                // wrote new files, should checkpoint()
                writer.Checkpoint();

                // if there is a reader open, reopen it to reflect the updates
                if (reader != null)
                {
                    SegmentReader newReader = new SegmentReader(Info, reader, liveDocs, Info.Info.DocCount - Info.DelCount - pendingDeleteCount);
                    bool          reopened  = false;
                    try
                    {
                        reader.DecRef();
                        reader   = newReader;
                        reopened = true;
                    }
                    finally
                    {
                        if (!reopened)
                        {
                            newReader.DecRef();
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Sole constructor. </summary>
 public Lucene42Codec()
     : base()
 {
     postingsFormat  = new PerFieldPostingsFormatAnonymousClass(this);
     docValuesFormat = new PerFieldDocValuesFormatAnonymousClass(this);
 }
 public Lucene46CodecAnonymousInnerClassHelper(TestRuleSetupAndRestoreClassEnv outerInstance, PostingsFormat format, DocValuesFormat dvFormat)
 {
     this.outerInstance = outerInstance;
     this.format        = format;
     this.dvFormat      = dvFormat;
 }
Exemplo n.º 6
0
        public override void Before()
        {
            // LUCENENET specific - SOLR setup code removed

            // if verbose: print some debugging stuff about which codecs are loaded.
            if (LuceneTestCase.Verbose)
            {
                // LUCENENET: Only list the services if the underlying ICodecFactory
                // implements IServiceListable
                if (Codec.GetCodecFactory() is IServiceListable)
                {
                    ICollection <string> codecs = Codec.AvailableCodecs;
                    foreach (string codec in codecs)
                    {
                        Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name);
                    }
                }

                // LUCENENET: Only list the services if the underlying IPostingsFormatFactory
                // implements IServiceListable
                if (PostingsFormat.GetPostingsFormatFactory() is IServiceListable)
                {
                    ICollection <string> postingsFormats = PostingsFormat.AvailablePostingsFormats;
                    foreach (string postingsFormat in postingsFormats)
                    {
                        Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name);
                    }
                }
            }

            savedInfoStream = InfoStream.Default;
            Random random = LuceneTestCase.Random;
            bool   v      = random.NextBoolean();

            if (LuceneTestCase.UseInfoStream)
            {
                InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out);
            }
            else if (v)
            {
                InfoStream.Default = new NullInfoStream();
            }

            Type targetClass = LuceneTestCase.TestType;

            avoidCodecs = new JCG.HashSet <string>();
            var suppressCodecsAttribute = targetClass.GetCustomAttribute <LuceneTestCase.SuppressCodecsAttribute>();

            if (suppressCodecsAttribute != null)
            {
                avoidCodecs.UnionWith(suppressCodecsAttribute.Value);
            }

            // set back to default
            LuceneTestCase.OldFormatImpersonationIsActive = false;

            savedCodec = Codec.Default;
            int randomVal = random.Next(10);

            if ("Lucene3x".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                          "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                          "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                          randomVal == 3 &&
                                                                                          !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup
            {
                codec = Codec.ForName("Lucene3x");
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is PreFlexRWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
                LuceneTestCase.OldFormatImpersonationIsActive = true;
            }
            else if ("Lucene40".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 0 &&
                                                                                               !ShouldAvoidCodec("Lucene40"))) // 4.0 setup
            {
                codec = Codec.ForName("Lucene40");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene40RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your IPostingsFormatFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene41".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 1 &&
                                                                                               !ShouldAvoidCodec("Lucene41")))
            {
                codec = Codec.ForName("Lucene41");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene41RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene42".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 2 &&
                                                                                               !ShouldAvoidCodec("Lucene42")))
            {
                codec = Codec.ForName("Lucene42");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene42RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene45".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 5 &&
                                                                                               !ShouldAvoidCodec("Lucene45")))
            {
                codec = Codec.ForName("Lucene45");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene45RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if (("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) == false) ||
                     ("random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) == false))
            {
                // the user wired postings or DV: this is messy
                // refactor into RandomCodec....

                PostingsFormat format;
                if ("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
                {
                    format = PostingsFormat.ForName("Lucene41");
                }
                else if ("MockRandom".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
                {
                    format = new MockRandomPostingsFormat(new J2N.Randomizer(random.NextInt64()));
                }
                else
                {
                    format = PostingsFormat.ForName(LuceneTestCase.TestPostingsFormat);
                }

                DocValuesFormat dvFormat;
                if ("random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal))
                {
                    dvFormat = DocValuesFormat.ForName("Lucene45");
                }
                else
                {
                    dvFormat = DocValuesFormat.ForName(LuceneTestCase.TestDocValuesFormat);
                }

                codec = new Lucene46CodecAnonymousClass(format, dvFormat);
            }
            else if ("SimpleText".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 9 && LuceneTestCase.Rarely(random) && !ShouldAvoidCodec("SimpleText")))
            {
                codec = new SimpleTextCodec();
            }
            else if ("CheapBastard".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 8 && !ShouldAvoidCodec("CheapBastard") && !ShouldAvoidCodec("Lucene41")))
            {
                // we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses.
                codec = new CheapBastardCodec();
            }
            else if ("Asserting".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 6 && !ShouldAvoidCodec("Asserting")))
            {
                codec = new AssertingCodec();
            }
            else if ("Compressing".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 5 && !ShouldAvoidCodec("Compressing")))
            {
                codec = CompressingCodec.RandomInstance(random);
            }
            else if (!"random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal))
            {
                codec = Codec.ForName(LuceneTestCase.TestCodec);
            }
            else if ("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
            {
                codec = new RandomCodec(random, avoidCodecs);
            }
            else
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(false);
                }
            }
            Codec.Default = codec;

            // Initialize locale/ timezone.

            string testTimeZone = SystemProperties.GetProperty("tests:timezone", "random");  // LUCENENET specific - reformatted with :

            // LUCENENET: We need to ensure our random generator stays consistent here so we can repeat the session exactly,
            // so always call this whether the return value is useful or not.
            CultureInfo randomLocale = LuceneTestCase.RandomCulture(random);

            // LUCENENET: Allow NUnit properties to set the culture and respect that culture over our random one.
            // Note that SetCultureAttribute may also be on the test method, but we don't need to deal with that here.
            if (targetClass.Assembly.HasAttribute <NUnit.Framework.SetCultureAttribute>(inherit: true) ||
                targetClass.HasAttribute <NUnit.Framework.SetCultureAttribute>(inherit: true))
            {
                locale = CultureInfo.CurrentCulture;
            }
            else
            {
                // LUCENENET: Accept either tests:culture or tests:locale (culture preferred).
                string testLocale = SystemProperties.GetProperty("tests:culture", SystemProperties.GetProperty("tests:locale", "random")); // LUCENENET specific - reformatted with :

                // Always pick a random one for consistency (whether tests.locale was specified or not).
                savedLocale = CultureInfo.CurrentCulture;

                locale = testLocale.Equals("random", StringComparison.Ordinal) ? randomLocale : LuceneTestCase.CultureForName(testLocale);
#if FEATURE_CULTUREINFO_CURRENTCULTURE_SETTER
                CultureInfo.CurrentCulture = locale;
#else
                Thread.CurrentThread.CurrentCulture = locale;
#endif
            }

            // TimeZone.getDefault will set user.timezone to the default timezone of the user's locale.
            // So store the original property value and restore it at end.
            // LUCENENET specific - commented
            //restoreProperties["user:timezone"] = SystemProperties.GetProperty("user:timezone");
            savedTimeZone = TimeZoneInfo.Local;
            TimeZoneInfo randomTimeZone = LuceneTestCase.RandomTimeZone(random);
            timeZone = testTimeZone.Equals("random", StringComparison.Ordinal) ? randomTimeZone : TimeZoneInfo.FindSystemTimeZoneById(testTimeZone);
            //TimeZone.Default = TimeZone; // LUCENENET NOTE: There doesn't seem to be an equivalent to this, but I don't think we need it.
            similarity = random.NextBoolean() ? (Similarity) new DefaultSimilarity() : new RandomSimilarityProvider(random);

            // Check codec restrictions once at class level.
            try
            {
                CheckCodecRestrictions(codec);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + avoidCodecs);
                throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
            }
        }
Exemplo n.º 7
0
            internal virtual DocValuesConsumer GetInstance(FieldInfo field)
            {
                DocValuesFormat format = null;

                if (field.DocValuesGen != -1)
                {
                    string formatName = field.GetAttribute(PER_FIELD_FORMAT_KEY);
                    // this means the field never existed in that segment, yet is applied updates
                    if (formatName != null)
                    {
                        format = DocValuesFormat.ForName(formatName);
                    }
                }
                if (format == null)
                {
                    format = outerInstance.GetDocValuesFormatForField(field.Name);
                }
                if (format == null)
                {
                    throw new InvalidOperationException("invalid null DocValuesFormat for field=\"" + field.Name + "\"");
                }
                string formatName_ = format.Name;

                string previousValue = field.PutAttribute(PER_FIELD_FORMAT_KEY, formatName_);

                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(field.DocValuesGen != -1 || previousValue == null, "formatName={0} prevValue={1}", formatName_, previousValue);
                }

                int?suffix = null;

                if (!formats.TryGetValue(format, out ConsumerAndSuffix consumer) || consumer == null)
                {
                    // First time we are seeing this format; create a new instance

                    if (field.DocValuesGen != -1)
                    {
                        string suffixAtt = field.GetAttribute(PER_FIELD_SUFFIX_KEY);
                        // even when dvGen is != -1, it can still be a new field, that never
                        // existed in the segment, and therefore doesn't have the recorded
                        // attributes yet.
                        if (suffixAtt != null)
                        {
                            suffix = Convert.ToInt32(suffixAtt, CultureInfo.InvariantCulture);
                        }
                    }

                    if (suffix == null)
                    {
                        // bump the suffix
                        if (!suffixes.TryGetValue(formatName_, out suffix) || suffix == null)
                        {
                            suffix = 0;
                        }
                        else
                        {
                            suffix = suffix + 1;
                        }
                    }
                    suffixes[formatName_] = suffix;

                    string segmentSuffix = GetFullSegmentSuffix(segmentWriteState.SegmentSuffix, GetSuffix(formatName_, Convert.ToString(suffix, CultureInfo.InvariantCulture)));
                    consumer          = new ConsumerAndSuffix();
                    consumer.Consumer = format.FieldsConsumer(new SegmentWriteState(segmentWriteState, segmentSuffix));
                    consumer.Suffix   = suffix.Value; // LUCENENET NOTE: At this point suffix cannot be null
                    formats[format]   = consumer;
                }
                else
                {
                    // we've already seen this format, so just grab its suffix
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(suffixes.ContainsKey(formatName_));
                    }
                    suffix = consumer.Suffix;
                }

                previousValue = field.PutAttribute(PER_FIELD_SUFFIX_KEY, Convert.ToString(suffix, CultureInfo.InvariantCulture));
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(field.DocValuesGen != -1 || previousValue == null, "suffix={0} prevValue={1}", suffix, previousValue);
                }

                // TODO: we should only provide the "slice" of FIS
                // that this DVF actually sees ...
                return(consumer.Consumer);
            }
Exemplo n.º 8
0
 /// <summary>
 /// Returns the <see cref="DocValuesProducer"/> for the given generation. </summary>
 internal DocValuesProducer GetDocValuesProducer(long?gen, SegmentCommitInfo si, IOContext context, Directory dir, DocValuesFormat dvFormat, IList <FieldInfo> infos, int termsIndexDivisor)
 {
     lock (this)
     {
         RefCount <DocValuesProducer> dvp;
         if (!(genDVProducers.TryGetValue(gen, out dvp)))
         {
             dvp = NewDocValuesProducer(si, context, dir, dvFormat, gen, infos, termsIndexDivisor);
             Debug.Assert(dvp != null);
             genDVProducers[gen] = dvp;
         }
         else
         {
             dvp.IncRef();
         }
         return(dvp.Get());
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Sole constructor. </summary>
 public Lucene45Codec()
     : base("Lucene45")
 {
     postingsFormat = new PerFieldPostingsFormatAnonymousInnerClassHelper(this);
     docValuesFormat = new PerFieldDocValuesFormatAnonymousInnerClassHelper(this);
 }
 public Lucene46CodecAnonymousClass(PostingsFormat format, DocValuesFormat dvFormat)
 {
     this.format   = format;
     this.dvFormat = dvFormat;
 }
 public Lucene46CodecAnonymousInnerClassHelper(TestRuleSetupAndRestoreClassEnv outerInstance, PostingsFormat format, DocValuesFormat dvFormat)
 {
     this.OuterInstance = outerInstance;
     this.Format = format;
     this.DvFormat = dvFormat;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Returns the <see cref="DocValuesProducer"/> for the given generation. </summary>
 internal DocValuesProducer GetDocValuesProducer(long?gen, SegmentCommitInfo si, IOContext context, Directory dir, DocValuesFormat dvFormat, IList <FieldInfo> infos, int termsIndexDivisor)
 {
     UninterruptableMonitor.Enter(this);
     try
     {
         if (!genDVProducers.TryGetValue(gen, out RefCount <DocValuesProducer> dvp))
         {
             dvp = NewDocValuesProducer(si, context, dir, dvFormat, gen, infos, termsIndexDivisor);
             if (Debugging.AssertsEnabled)
             {
                 Debugging.Assert(dvp != null);
             }
             genDVProducers[gen] = dvp;
         }
         else
         {
             dvp.IncRef();
         }
         return(dvp.Get());
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
Exemplo n.º 13
0
 /// <param name="oldFormatImpersonationIsActive">
 /// LUCENENET specific
 /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
 /// </param>
 public Lucene42RWCodec(bool oldFormatImpersonationIsActive) : base()
 {
     Dv = new Lucene42RWDocValuesFormat(oldFormatImpersonationIsActive);
     fieldInfosFormat = new Lucene42FieldInfosFormatAnonymousInnerClassHelper(oldFormatImpersonationIsActive);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Sole constructor. </summary>
 public Lucene46Codec()
     : base()
 {
     postingsFormat  = new PerFieldPostingsFormatAnonymousInnerClassHelper(this);
     docValuesFormat = new PerFieldDocValuesFormatAnonymousInnerClassHelper(this);
 }
Exemplo n.º 15
0
 /// <param name="oldFormatImpersonationIsActive">
 /// LUCENENET specific
 /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/>
 /// </param>
 public Lucene42RWCodec(bool oldFormatImpersonationIsActive) : base()
 {
     Dv = new Lucene42RWDocValuesFormat(oldFormatImpersonationIsActive);
     fieldInfosFormat = new Lucene42FieldInfosFormatAnonymousInnerClassHelper(oldFormatImpersonationIsActive);
 }
Exemplo n.º 16
0
        private RefCount <DocValuesProducer> NewDocValuesProducer(SegmentCommitInfo si, IOContext context, Directory dir, DocValuesFormat dvFormat, long?gen, IList <FieldInfo> infos, int termsIndexDivisor)
        {
            Directory dvDir         = dir;
            string    segmentSuffix = "";

            if ((long)gen != -1)
            {
                dvDir         = si.Info.Dir;                                        // gen'd files are written outside CFS, so use SegInfo directory
                segmentSuffix = ((long)gen).ToString(CultureInfo.InvariantCulture); //Convert.ToString((long)gen, Character.MAX_RADIX);
            }

            // set SegmentReadState to list only the fields that are relevant to that gen
            SegmentReadState srs = new SegmentReadState(dvDir, si.Info, new FieldInfos(infos.ToArray()), context, termsIndexDivisor, segmentSuffix);

            return(new RefCountHelper(this, dvFormat.FieldsProducer(srs), gen));
        }
Exemplo n.º 17
0
 public Lucene46CodecAnonymousClass2(DocValuesFormat format)
 {
     this.format = format;
 }
Exemplo n.º 18
0
 public Lucene46CodecAnonymousInnerClassHelper(TestPerFieldDocValuesFormat outerInstance, DocValuesFormat fast, DocValuesFormat slow)
 {
     this.OuterInstance = outerInstance;
     this.Fast          = fast;
     this.Slow          = slow;
 }
        public override void Before(LuceneTestCase testInstance)
        {
            // LUCENENET specific - SOLR setup code removed

            // if verbose: print some debugging stuff about which codecs are loaded.
            if (LuceneTestCase.VERBOSE)
            {
                ICollection <string> codecs = Codec.AvailableCodecs;
                foreach (string codec in codecs)
                {
                    Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name);
                }

                ICollection <string> postingsFormats = PostingsFormat.AvailablePostingsFormats;
                foreach (string postingsFormat in postingsFormats)
                {
                    Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name);
                }
            }

            savedInfoStream = InfoStream.Default;
            Random random = LuceneTestCase.Random;
            bool   v      = random.NextBoolean();

            if (LuceneTestCase.INFOSTREAM)
            {
                InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out);
            }
            else if (v)
            {
                InfoStream.Default = new NullInfoStream();
            }

            Type targetClass = testInstance?.GetType() ?? LuceneTestCase.GetTestClass();

            avoidCodecs = new JCG.HashSet <string>();
            var suppressCodecsAttribute = targetClass.GetTypeInfo().GetCustomAttribute <LuceneTestCase.SuppressCodecsAttribute>();

            if (suppressCodecsAttribute != null)
            {
                avoidCodecs.UnionWith(suppressCodecsAttribute.Value);
            }

            // set back to default
            LuceneTestCase.OldFormatImpersonationIsActive = false;

            savedCodec = Codec.Default;
            int randomVal = random.Next(10);

            if ("Lucene3x".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) &&
                                                                                           "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) &&
                                                                                           "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) &&
                                                                                           randomVal == 3 &&
                                                                                           !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup
            {
                codec = Codec.ForName("Lucene3x");
                Debug.Assert((codec is PreFlexRWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
            }
            else if ("Lucene40".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) &&
                                                                                                randomVal == 0 &&
                                                                                                !ShouldAvoidCodec("Lucene40"))) // 4.0 setup
            {
                codec = Codec.ForName("Lucene40");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                Debug.Assert((codec is Lucene40RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                Debug.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your IPostingsFormatFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
            }
            else if ("Lucene41".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) &&
                                                                                                randomVal == 1 &&
                                                                                                !ShouldAvoidCodec("Lucene41")))
            {
                codec = Codec.ForName("Lucene41");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                Debug.Assert((codec is Lucene41RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
            }
            else if ("Lucene42".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) &&
                                                                                                randomVal == 2 &&
                                                                                                !ShouldAvoidCodec("Lucene42")))
            {
                codec = Codec.ForName("Lucene42");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                Debug.Assert((codec is Lucene42RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
            }
            else if ("Lucene45".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) &&
                                                                                                "random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) &&
                                                                                                randomVal == 5 &&
                                                                                                !ShouldAvoidCodec("Lucene45")))
            {
                codec = Codec.ForName("Lucene45");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                Debug.Assert((codec is Lucene45RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
            }
            else if (("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal) == false) ||
                     ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal) == false))
            {
                // the user wired postings or DV: this is messy
                // refactor into RandomCodec....

                PostingsFormat format;
                if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal))
                {
                    format = PostingsFormat.ForName("Lucene41");
                }
                else if ("MockRandom".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal))
                {
                    format = new MockRandomPostingsFormat(new Random(random.Next()));
                }
                else
                {
                    format = PostingsFormat.ForName(LuceneTestCase.TEST_POSTINGSFORMAT);
                }

                DocValuesFormat dvFormat;
                if ("random".Equals(LuceneTestCase.TEST_DOCVALUESFORMAT, StringComparison.Ordinal))
                {
                    dvFormat = DocValuesFormat.ForName("Lucene45");
                }
                else
                {
                    dvFormat = DocValuesFormat.ForName(LuceneTestCase.TEST_DOCVALUESFORMAT);
                }

                codec = new Lucene46CodecAnonymousInnerClassHelper(this, format, dvFormat);
            }
            else if ("SimpleText".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 9 && LuceneTestCase.Rarely(random) && !ShouldAvoidCodec("SimpleText")))
            {
                codec = new SimpleTextCodec();
            }
            else if ("CheapBastard".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 8 && !ShouldAvoidCodec("CheapBastard") && !ShouldAvoidCodec("Lucene41")))
            {
                // we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses.
                codec = new CheapBastardCodec();
            }
            else if ("Asserting".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 6 && !ShouldAvoidCodec("Asserting")))
            {
                codec = new AssertingCodec();
            }
            else if ("Compressing".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal) && randomVal == 5 && !ShouldAvoidCodec("Compressing")))
            {
                codec = CompressingCodec.RandomInstance(random);
            }
            else if (!"random".Equals(LuceneTestCase.TEST_CODEC, StringComparison.Ordinal))
            {
                codec = Codec.ForName(LuceneTestCase.TEST_CODEC);
            }
            else if ("random".Equals(LuceneTestCase.TEST_POSTINGSFORMAT, StringComparison.Ordinal))
            {
                codec = new RandomCodec(random, avoidCodecs);
            }
            else
            {
                Debug.Assert(false);
            }
            Codec.Default = codec;

            // Initialize locale/ timezone.
            string testLocale   = SystemProperties.GetProperty("tests.locale", "random");
            string testTimeZone = SystemProperties.GetProperty("tests.timezone", "random");

            // Always pick a random one for consistency (whether tests.locale was specified or not).
            savedLocale = CultureInfo.CurrentCulture;
            CultureInfo randomLocale = LuceneTestCase.RandomCulture(random);

            locale = testLocale.Equals("random", StringComparison.Ordinal) ? randomLocale : LuceneTestCase.CultureForName(testLocale);
#if NETSTANDARD
            CultureInfo.CurrentCulture = locale;
#else
            Thread.CurrentThread.CurrentCulture = locale;
#endif

            // TimeZone.getDefault will set user.timezone to the default timezone of the user's locale.
            // So store the original property value and restore it at end.
            restoreProperties["user.timezone"] = SystemProperties.GetProperty("user.timezone");
            savedTimeZone = TimeZoneInfo.Local;
            TimeZoneInfo randomTimeZone = LuceneTestCase.RandomTimeZone(random);
            timeZone = testTimeZone.Equals("random", StringComparison.Ordinal) ? randomTimeZone : TimeZoneInfo.FindSystemTimeZoneById(testTimeZone);
            //TimeZone.Default = TimeZone; // LUCENENET NOTE: There doesn't seem to be an equivalent to this, but I don't think we need it.
            similarity = random.NextBoolean() ? (Similarity) new DefaultSimilarity() : new RandomSimilarityProvider(random);

            // Check codec restrictions once at class level.
            try
            {
                CheckCodecRestrictions(codec);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + Arrays.ToString(avoidCodecs.ToArray()));
                throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
            }
        }
 public Lucene46CodecAnonymousInnerClassHelper(TestPerFieldDocValuesFormat outerInstance, DocValuesFormat fast, DocValuesFormat slow)
 {
     this.OuterInstance = outerInstance;
     this.Fast = fast;
     this.Slow = slow;
 }
Exemplo n.º 21
0
        private RefCount <DocValuesProducer> NewDocValuesProducer(SegmentCommitInfo si, IOContext context, Directory dir, DocValuesFormat dvFormat, long gen, IList <FieldInfo> infos, int termsIndexDivisor)
        {
            Directory dvDir         = dir;
            string    segmentSuffix = "";

            if (gen != -1)
            {
                dvDir = si.Info.Dir; // gen'd files are written outside CFS, so use SegInfo directory
                // LUCENENET specific: We created the segments names wrong in 4.8.0-beta00001 - 4.8.0-beta00015,
                // so we added a switch to be able to read these indexes in later versions. This logic as well as an
                // optimization on the first 100 segment values is implmeneted in SegmentInfos.SegmentNumberToString().
                segmentSuffix = SegmentInfos.SegmentNumberToString(gen);
            }

            // set SegmentReadState to list only the fields that are relevant to that gen
            SegmentReadState srs = new SegmentReadState(dvDir, si.Info, new FieldInfos(infos.ToArray()), context, termsIndexDivisor, segmentSuffix);

            return(new RefCountHelper(this, dvFormat.FieldsProducer(srs), gen));
        }