Exemplo n.º 1
0
 public override void Run()
 {
     try
     {
         Document doc   = new Document();
         Field    field = NewTextField("field", "testData", Field.Store.YES);
         doc.Add(field);
         using (IndexWriter writer = new IndexWriter(Dir, OuterInstance.NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))))
         {
             if (IwConstructed.CurrentCount > 0)
             {
                 IwConstructed.Signal();
             }
             StartIndexing_Renamed.Wait();
             writer.AddDocument(doc);
         }
     }
     catch (Exception e)
     {
         Failed  = true;
         Failure = e;
         Console.WriteLine(e.ToString());
         return;
     }
 }
Exemplo n.º 2
0
        public static void CreateIndex(Random random, Directory dir, bool multiSegment)
        {
            IndexWriter.Unlock(dir);
            IndexWriter w = new IndexWriter(dir, LuceneTestCase.NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(new LogDocMergePolicy()));

            for (int i = 0; i < 100; i++)
            {
                w.AddDocument(CreateDocument(i, 4));
                if (multiSegment && (i % 10) == 0)
                {
                    w.Commit();
                }
            }

            if (!multiSegment)
            {
                w.ForceMerge(1);
            }

            w.Dispose();

            DirectoryReader r = DirectoryReader.Open(dir);

            if (multiSegment)
            {
                Assert.IsTrue(r.Leaves.Count > 1);
            }
            else
            {
                Assert.IsTrue(r.Leaves.Count == 1);
            }
            r.Dispose();
        }
Exemplo n.º 3
0
        public static void IndexSerial(Random random, IDictionary <string, Document> docs, Directory dir)
        {
            IndexWriter w = new IndexWriter(dir, LuceneTestCase.NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy()));

            // index all docs in a single thread
            IEnumerator <Document> iter = docs.Values.GetEnumerator();

            while (iter.MoveNext())
            {
                Document d = iter.Current;
                List <IndexableField> fields = new List <IndexableField>();
                fields.AddRange(d.Fields);
                // put fields in same order each time
                fields.Sort(fieldNameComparator);

                Document d1 = new Document();
                for (int i = 0; i < fields.Count; i++)
                {
                    d1.Add(fields[i]);
                }
                w.AddDocument(d1);
                // System.out.println("indexing "+d1);
            }

            w.Dispose();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a <see cref="RandomIndexWriter"/> with a random config: Uses <see cref="LuceneTestCase.TEST_VERSION_CURRENT"/>.
 /// </summary>
 public RandomIndexWriter(Random r, Directory dir, Analyzer a)
     : this(r, dir, LuceneTestCase.NewIndexWriterConfig(r, LuceneTestCase.TEST_VERSION_CURRENT, a))
 {
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="RandomIndexWriter"/> with a random config.
        /// </summary>
        /// <param name="luceneTestCase">The current test instance.</param>
        /// <param name="r"></param>
        /// <param name="dir"></param>
        /// <param name="v"></param>
        /// <param name="a"></param>

        // LUCENENET specific
        // Similarity and TimeZone parameters allow a RandomIndexWriter to be
        // created without adding a dependency on
        // <see cref="LuceneTestCase.ClassEnv.Similarity"/> and
        // <see cref="LuceneTestCase.ClassEnv.TimeZone"/>
        public RandomIndexWriter(LuceneTestCase luceneTestCase, Random r, Directory dir, LuceneVersion v, Analyzer a)
            : this(r, dir, luceneTestCase.NewIndexWriterConfig(r, v, a))
        {
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create a <see cref="RandomIndexWriter"/> with a random config: Uses <see cref="LuceneTestCase.TEST_VERSION_CURRENT"/> and <see cref="MockAnalyzer"/>.
 /// </summary>
 /// <param name="luceneTestCase">The current test instance.</param>
 /// <param name="r"></param>
 /// <param name="dir"></param>
 // LUCENENET specific
 // Similarity and TimeZone parameters allow a RandomIndexWriter to be
 // created without adding a dependency on
 // <see cref="LuceneTestCase.ClassEnv.Similarity"/> and
 // <see cref="LuceneTestCase.ClassEnv.TimeZone"/>
 public RandomIndexWriter(LuceneTestCase luceneTestCase, Random r, Directory dir)
     : this(r, dir, luceneTestCase.NewIndexWriterConfig(r, LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(r)))
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and MockAnalyzer
 ///
 /// LUCENENET specific
 /// Similarity and TimeZone parameters allow a RandomIndexWriter to be
 /// created without adding a dependency on
 /// <see cref="LuceneTestCase.ClassEnv.Similarity"/> and
 /// <see cref="LuceneTestCase.ClassEnv.TimeZone"/>
 /// </summary>
 public RandomIndexWriter(Random r, Directory dir, Similarity similarity, TimeZoneInfo timezone)
     : this(r, dir, LuceneTestCase.NewIndexWriterConfig(r, LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(r), similarity, timezone))
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a RandomIndexWriter with a random config
 ///
 /// LUCENENET specific
 /// Similarity and TimeZone parameters allow a RandomIndexWriter to be
 /// created without adding a dependency on
 /// <see cref="LuceneTestCase.ClassEnv.Similarity"/> and
 /// <see cref="LuceneTestCase.ClassEnv.TimeZone"/>
 /// </summary>
 public RandomIndexWriter(Random r, Directory dir, LuceneVersion v, Analyzer a, Similarity similarity, TimeZoneInfo timezone)
     : this(r, dir, LuceneTestCase.NewIndexWriterConfig(r, v, a, similarity, timezone))
 {
 }