Esempio n. 1
0
        /*
         * Run one indexer and 2 searchers against single index as
         * stress test.
         */
        public virtual void  RunTest(Directory directory)
        {
            TimedThread[] threads = new TimedThread[4];

            IndexWriter writer = new MockIndexWriter(this, directory, true, ANALYZER, true);

            writer.SetMaxBufferedDocs(7);
            writer.SetMergeFactor(3);

            // Establish a base index of 100 docs:
            for (int i = 0; i < 100; i++)
            {
                Document d = new Document();
                d.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
                d.Add(new Field("contents", English.IntToEnglish(i), Field.Store.NO, Field.Index.ANALYZED));
                writer.AddDocument(d);
            }
            writer.Commit();

            IndexReader r = IndexReader.Open(directory);

            Assert.AreEqual(100, r.NumDocs());
            r.Close();

            IndexerThread indexerThread = new IndexerThread(writer, threads);

            threads[0] = indexerThread;
            indexerThread.Start();

            IndexerThread indexerThread2 = new IndexerThread(writer, threads);

            threads[1] = indexerThread2;
            indexerThread2.Start();

            SearcherThread searcherThread1 = new SearcherThread(directory, threads);

            threads[2] = searcherThread1;
            searcherThread1.Start();

            SearcherThread searcherThread2 = new SearcherThread(directory, threads);

            threads[3] = searcherThread2;
            searcherThread2.Start();

            indexerThread.Join();
            indexerThread2.Join();
            searcherThread1.Join();
            searcherThread2.Join();

            writer.Close();

            Assert.IsTrue(!indexerThread.failed, "hit unexpected exception in indexer");
            Assert.IsTrue(!indexerThread2.failed, "hit unexpected exception in indexer2");
            Assert.IsTrue(!searcherThread1.failed, "hit unexpected exception in search1");
            Assert.IsTrue(!searcherThread2.failed, "hit unexpected exception in search2");
            //System.out.println("    Writer: " + indexerThread.count + " iterations");
            //System.out.println("Searcher 1: " + searcherThread1.count + " searchers created");
            //System.out.println("Searcher 2: " + searcherThread2.count + " searchers created");
        }
 public override void  DoWork()
 {
     // Update all 100 docs...
     for (int i = 0; i < 100; i++)
     {
         Document d = new Document();
         d.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
         d.Add(new Field("contents", English.IntToEnglish(i + 10 * count), Field.Store.NO, Field.Index.ANALYZED));
         writer.UpdateDocument(new Term("id", System.Convert.ToString(i)), d);
     }
 }
Esempio n. 3
0
        public virtual void  InitIndex(Directory dir)
        {
            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED, null);

            for (int j = 0; j < 7; j++)
            {
                Document d = new Document();
                int      n = RANDOM.Next();
                d.Add(new Field("contents", English.IntToEnglish(n), Field.Store.NO, Field.Index.ANALYZED));
                writer.AddDocument(d, null);
            }
            writer.Close();
        }
Esempio n. 4
0
            public virtual void  Update(IndexWriter writer)
            {
                // Add 10 docs:
                for (int j = 0; j < 10; j++)
                {
                    Document d = new Document();
                    int      n = Enclosing_Instance.RANDOM.Next();
                    d.Add(new Field("id", System.Convert.ToString(nextID++), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    d.Add(new Field("contents", English.IntToEnglish(n), Field.Store.NO, Field.Index.ANALYZED));
                    writer.AddDocument(d, null);
                }

                // Delete 5 docs:
                int deleteID = nextID - 1;

                for (int j = 0; j < 5; j++)
                {
                    writer.DeleteDocuments(null, new Term("id", "" + deleteID));
                    deleteID -= 2;
                }
            }