Пример #1
0
        public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, int range, Directory dir)
        {
            System.Collections.Hashtable docs = new System.Collections.Hashtable();
            IndexWriter w = new MockIndexWriter(this, dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);

            w.UseCompoundFile = false;

            /*
             * w.setMaxMergeDocs(Integer.MAX_VALUE);
             * w.setMaxFieldLength(10000);
             * w.setRAMBufferSizeMB(1);
             * w.setMergeFactor(10);
             ***/

            // force many merges
            w.MergeFactor = mergeFactor;
            w.SetRAMBufferSizeMB(.1);
            w.SetMaxBufferedDocs(maxBufferedDocs);

            threads = new IndexingThread[nThreads];
            for (int i = 0; i < threads.Length; i++)
            {
                IndexingThread th = new IndexingThread();
                th.w            = w;
                th.base_Renamed = 1000000 * i;
                th.range        = range;
                th.iterations   = iterations;
                threads[i]      = th;
            }

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Start();
            }
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            // w.optimize();
            //w.close();

            for (int i = 0; i < threads.Length; i++)
            {
                IndexingThread th = threads[i];
                lock (th)
                {
                    CollectionsHelper.AddAllIfNotContains(docs, th.docs);
                }
            }

            _TestUtil.CheckIndex(dir);
            DocsAndWriter dw = new DocsAndWriter();

            dw.docs   = docs;
            dw.writer = w;
            return(dw);
        }