/** Creates an index for sorting. */
        public void CreateIndex(Directory dir, int numDocs, Random random)
        {
            IList <int> ids = new List <int>();

            for (int i = 0; i < numDocs; i++)
            {
                ids.Add(i * 10);
            }
            // shuffle them for indexing
            ids.Shuffle(Random);

            if (Verbose)
            {
                Console.WriteLine("Shuffled IDs for indexing: " + Collections.ToString(ids));
            }

            PositionsTokenStream positions = new PositionsTokenStream();
            IndexWriterConfig    conf      = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));

            conf.SetMaxBufferedDocs(4);                               // create some segments
            conf.SetSimilarity(new NormsSimilarity(conf.Similarity)); // for testing norms field
            using (RandomIndexWriter writer = new RandomIndexWriter(random, dir, conf))
            {
                writer.DoRandomForceMerge = (false);
                foreach (int id in ids)
                {
                    writer.AddDocument(Doc(id, positions));
                }
                // delete some documents
                writer.Commit();
                foreach (int id in ids)
                {
                    if (random.NextDouble() < 0.2)
                    {
                        if (Verbose)
                        {
                            Console.WriteLine("delete doc_id " + id);
                        }
                        writer.DeleteDocuments(new Term(ID_FIELD, id.ToString()));
                    }
                }
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            dir = NewDirectory();
            IndexWriterConfig iwConfig = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random));

            iwConfig.SetMergePolicy(NewLogMergePolicy());
            iwConfig.SetSimilarity(sim);
            RandomIndexWriter iw = new RandomIndexWriter(Random, dir, iwConfig);

            Document doc = new Document();

            doc.Add(new TextField("text", "this is a test test test", Field.Store.NO));
            iw.AddDocument(doc);

            doc = new Document();
            doc.Add(new TextField("text", "second test", Field.Store.NO));
            iw.AddDocument(doc);

            reader   = iw.GetReader();
            searcher = NewSearcher(reader);
            iw.Dispose();
        }