Lucene.Net.Index.TestIndexWriterExceptions.RandomTVSetting C# (CSharp) Method

RandomTVSetting() private method

private RandomTVSetting ( Random random ) : Lucene.Net.Documents.Field.TermVector
random System.Random
return Lucene.Net.Documents.Field.TermVector
        private TermVector RandomTVSetting(Random random)
        {
            return tvSettings[random.Next(tvSettings.Length)];
        }
		

Usage Example

            override public void  Run()
            {
                Document doc = new Document();

                doc.Add(new Field("content1", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));
                doc.Add(new Field("content6", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));
                doc.Add(new Field("content2", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));
                doc.Add(new Field("content3", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.NO));

                doc.Add(new Field("content4", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));
                doc.Add(new Field("content5", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));

                doc.Add(new Field("content7", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)));

                Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random));

                doc.Add(idField);

                long stopTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + 3000;

                while ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) < stopTime)
                {
                    System.Threading.Thread.SetData(Enclosing_Instance.doFail, this);
                    System.String id = "" + r.Next(50);
                    idField.SetValue(id);
                    Term idTerm = new Term("id", id);
                    try
                    {
                        writer.UpdateDocument(idTerm, doc);
                    }
                    catch (System.SystemException re)
                    {
                        if (Lucene.Net.Index.TestIndexWriterExceptions.DEBUG)
                        {
                            System.Console.Out.WriteLine(SupportClass.ThreadClass.CurrentThread().Name + ": EXC: ");
                            System.Console.Out.WriteLine(re.StackTrace);
                        }
                        try
                        {
                            _TestUtil.CheckIndex(writer.GetDirectory());
                        }
                        catch (System.IO.IOException ioe)
                        {
                            System.Console.Out.WriteLine(SupportClass.ThreadClass.Current().Name + ": unexpected exception1");
                            System.Console.Out.WriteLine(ioe.StackTrace);
                            failure = ioe;
                            break;
                        }
                    }
                    catch (System.Exception t)
                    {
                        System.Console.Out.WriteLine(SupportClass.ThreadClass.Current().Name + ": unexpected exception2");
                        System.Console.Out.WriteLine(t.StackTrace);
                        failure = t;
                        break;
                    }

                    System.Threading.Thread.SetData(Enclosing_Instance.doFail, null);

                    // After a possible exception (above) I should be able
                    // to add a new document without hitting an
                    // exception:
                    try
                    {
                        writer.UpdateDocument(idTerm, doc);
                    }
                    catch (System.Exception t)
                    {
                        System.Console.Out.WriteLine(SupportClass.ThreadClass.Current().Name + ": unexpected exception3");
                        System.Console.Out.WriteLine(t.StackTrace);
                        failure = t;
                        break;
                    }
                }
            }