Add() 공개 메소드

Add an IndexReader.
public Add ( IndexReader reader ) : void
reader IndexReader
리턴 void
예제 #1
0
        public virtual void  TestIsCurrent()
        {
            Directory      dir1 = GetDir1();
            Directory      dir2 = GetDir2();
            ParallelReader pr   = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));

            Assert.IsTrue(pr.IsCurrent());
            IndexReader modifier = IndexReader.Open(dir1);

            modifier.SetNorm(0, "f1", 100);
            modifier.Close();

            // one of the two IndexReaders which ParallelReader is using
            // is not current anymore
            Assert.IsFalse(pr.IsCurrent());

            modifier = IndexReader.Open(dir2);
            modifier.SetNorm(0, "f3", 100);
            modifier.Close();

            // now both are not current anymore
            Assert.IsFalse(pr.IsCurrent());
        }
예제 #2
0
        public virtual void  TestIncompatibleIndexes()
        {
            // two documents:
            Directory dir1 = GetDir1();

            // one document only:
            Directory   dir2 = new MockRAMDirectory();
            IndexWriter w2   = new IndexWriter(dir2, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
            Document    d3   = new Document();

            d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
            w2.AddDocument(d3);
            w2.Close();

            ParallelReader pr = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            try
            {
                pr.Add(IndexReader.Open(dir2));
                Assert.Fail("didn't get exptected exception: indexes don't have same number of documents");
            }
            catch (System.ArgumentException e)
            {
                // expected exception
            }
        }
예제 #3
0
        // Fields 1 & 2 in one index, 3 & 4 in other, with ParallelReader:
        private Searcher Parallel()
        {
            Directory      dir1 = GetDir1();
            Directory      dir2 = GetDir2();
            ParallelReader pr   = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            return(new IndexSearcher(pr));
        }
예제 #4
0
        public virtual void  TestIsOptimized()
        {
            Directory dir1 = GetDir1();
            Directory dir2 = GetDir2();

            // add another document to ensure that the indexes are not optimized
            IndexWriter modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            Document    d        = new Document();

            d.Add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
            modifier.AddDocument(d);
            modifier.Close();

            modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            d        = new Document();
            d.Add(new Field("f2", "v2", Field.Store.YES, Field.Index.ANALYZED));
            modifier.AddDocument(d);
            modifier.Close();


            ParallelReader pr = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            Assert.IsFalse(pr.IsOptimized());
            pr.Close();

            modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            modifier.Optimize();
            modifier.Close();

            pr = new ParallelReader();
            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            // just one of the two indexes are optimized
            Assert.IsFalse(pr.IsOptimized());
            pr.Close();


            modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            modifier.Optimize();
            modifier.Close();

            pr = new ParallelReader();
            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            // now both indexes are optimized
            Assert.IsTrue(pr.IsOptimized());
            pr.Close();
        }
예제 #5
0
		public virtual void  TestFieldNames()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
            System.Collections.Generic.ICollection<string> fieldNames = pr.GetFieldNames(IndexReader.FieldOption.ALL);
			Assert.AreEqual(4, fieldNames.Count);
			Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f1"));
			Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f2"));
			Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f3"));
			Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f4"));
		}
예제 #6
0
        public virtual void  TestFieldNames()
        {
            Directory      dir1 = GetDir1();
            Directory      dir2 = GetDir2();
            ParallelReader pr   = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            System.Collections.Generic.ICollection <string> fieldNames = pr.GetFieldNames(IndexReader.FieldOption.ALL);
            Assert.AreEqual(4, fieldNames.Count);
            Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f1"));
            Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f2"));
            Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f3"));
            Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f4"));
        }
예제 #7
0
        public virtual void  TestParallelReader()
        {
            Directory dir1 = new MockRAMDirectory();

            TestIndexReaderReopen.CreateIndex(dir1, true);
            Directory dir2 = new MockRAMDirectory();

            TestIndexReaderReopen.CreateIndex(dir2, true);
            IndexReader r1 = IndexReader.Open(dir1, false);
            IndexReader r2 = IndexReader.Open(dir2, false);

            ParallelReader pr1 = new ParallelReader();

            pr1.Add(r1);
            pr1.Add(r2);

            PerformDefaultTests(pr1);
            pr1.Close();
            dir1.Close();
            dir2.Close();
        }
        public virtual void  TestIncompatibleIndexes()
        {
            // two documents:
            Directory dir1 = GetDir1();

            // one document only:
            Directory   dir2 = new MockRAMDirectory();
            IndexWriter w2   = new IndexWriter(dir2, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
            Document    d3   = new Document();

            d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
            w2.AddDocument(d3);
            w2.Close();

            ParallelReader pr = new ParallelReader();

            pr.Add(IndexReader.Open(dir1, false));

            Assert.Throws <ArgumentException>(() => pr.Add(IndexReader.Open(dir2, false)),
                                              "didn't get exptected exception: indexes don't have same number of documents");
        }
예제 #9
0
        public virtual void  TestAllTermDocs()
        {
            Directory      dir1 = GetDir1();
            Directory      dir2 = GetDir2();
            ParallelReader pr   = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));
            int      NUM_DOCS = 2;
            TermDocs td       = pr.TermDocs(null);

            for (int i = 0; i < NUM_DOCS; i++)
            {
                Assert.IsTrue(td.Next());
                Assert.AreEqual(i, td.Doc());
                Assert.AreEqual(1, td.Freq());
            }
            td.Close();
            pr.Close();
            dir1.Close();
            dir2.Close();
        }
예제 #10
0
        public virtual void  TestDocument()
        {
            Directory      dir1 = GetDir1();
            Directory      dir2 = GetDir2();
            ParallelReader pr   = new ParallelReader();

            pr.Add(IndexReader.Open(dir1));
            pr.Add(IndexReader.Open(dir2));

            Document doc11  = pr.Document(0, new MapFieldSelector(new System.String[] { "f1" }));
            Document doc24  = pr.Document(1, new MapFieldSelector(new System.Collections.ArrayList(new System.String[] { "f4" })));
            Document doc223 = pr.Document(1, new MapFieldSelector(new System.String[] { "f2", "f3" }));

            Assert.AreEqual(1, doc11.GetFields().Count);
            Assert.AreEqual(1, doc24.GetFields().Count);
            Assert.AreEqual(2, doc223.GetFields().Count);

            Assert.AreEqual("v1", doc11.Get("f1"));
            Assert.AreEqual("v2", doc24.Get("f4"));
            Assert.AreEqual("v2", doc223.Get("f2"));
            Assert.AreEqual("v2", doc223.Get("f3"));
        }
예제 #11
0
			protected internal override IndexReader OpenReader()
			{
				ParallelReader pr = new ParallelReader();
				pr.Add(IndexReader.Open(dir1));
				pr.Add(IndexReader.Open(dir2));
				return pr;
			}
예제 #12
0
			protected internal override IndexReader OpenReader()
			{
				ParallelReader pr = new ParallelReader();
				pr.Add(IndexReader.Open(dir3));
				pr.Add(IndexReader.Open(dir4));
				// Does not implement reopen, so
				// hits exception:
				pr.Add(new FilterIndexReader(IndexReader.Open(dir3)));
				return pr;
			}
예제 #13
0
		public virtual void  Test1()
		{
			ParallelReader pr = new ParallelReader();
			pr.Add(ir1);
			pr.Add(ir2);
			
			TermDocs td = pr.TermDocs();
			
			TermEnum te = pr.Terms();
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field1:brown", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field1:fox", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field1:jumps", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field1:quick", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field1:the", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field2:brown", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field2:fox", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field2:jumps", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field2:quick", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field2:the", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:dog", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:fox", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:jumps", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:lazy", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:over", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsTrue(te.Next());
			Assert.AreEqual("field3:the", te.Term.ToString());
			td.Seek(te.Term);
			Assert.IsTrue(td.Next());
			Assert.AreEqual(0, td.Doc);
			Assert.IsFalse(td.Next());
			Assert.IsFalse(te.Next());
		}
예제 #14
0
		public virtual void  TestParallelReader()
		{
			Directory dir1 = new MockRAMDirectory();
			TestIndexReaderReopen.CreateIndex(dir1, true);
			Directory dir2 = new MockRAMDirectory();
			TestIndexReaderReopen.CreateIndex(dir2, true);
			IndexReader r1 = IndexReader.Open(dir1, false);
            IndexReader r2 = IndexReader.Open(dir2, false);
			
			ParallelReader pr1 = new ParallelReader();
			pr1.Add(r1);
			pr1.Add(r2);
			
			PerformDefaultTests(pr1);
			pr1.Close();
			dir1.Close();
			dir2.Close();
		}
예제 #15
0
		public virtual void  TestReferenceCountingParallelReader()
		{
			for (int mode = 0; mode <= 1; mode++)
			{
				Directory dir1 = new MockRAMDirectory();
				CreateIndex(dir1, false);
				Directory dir2 = new MockRAMDirectory();
				CreateIndex(dir2, true);
				
				IndexReader reader1 = IndexReader.Open(dir1);
				AssertRefCountEquals(1, reader1);
				
				ParallelReader parallelReader1 = new ParallelReader(mode == 0);
				parallelReader1.Add(reader1);
				IndexReader initReader2 = IndexReader.Open(dir2);
				parallelReader1.Add(initReader2);
				ModifyIndex(1, dir2);
				AssertRefCountEquals(1 + mode, reader1);
				
				IndexReader parallelReader2 = parallelReader1.Reopen();
				// index1 hasn't changed, so parallelReader2 should share reader1 now with multiReader1
				AssertRefCountEquals(2 + mode, reader1);
				
				ModifyIndex(0, dir1);
				ModifyIndex(0, dir2);
				IndexReader reader2 = reader1.Reopen();
				AssertRefCountEquals(2 + mode, reader1);
				
				if (mode == 1)
				{
					initReader2.Close();
				}
				
				ModifyIndex(4, dir1);
				IndexReader reader3 = reader2.Reopen();
				AssertRefCountEquals(2 + mode, reader1);
				AssertRefCountEquals(1, reader2);
				
				parallelReader1.Close();
				AssertRefCountEquals(1 + mode, reader1);
				
				parallelReader1.Close();
				AssertRefCountEquals(1 + mode, reader1);
				
				if (mode == 1)
				{
					initReader2.Close();
				}
				
				reader1.Close();
				AssertRefCountEquals(1, reader1);
				
				parallelReader2.Close();
				AssertRefCountEquals(0, reader1);
				
				parallelReader2.Close();
				AssertRefCountEquals(0, reader1);
				
				reader3.Close();
				AssertRefCountEquals(0, reader1);
				AssertReaderClosed(reader1, true, false);
				
				reader2.Close();
				AssertRefCountEquals(0, reader1);
				AssertReaderClosed(reader1, true, false);
				
				reader2.Close();
				AssertRefCountEquals(0, reader1);
				
				reader3.Close();
				AssertRefCountEquals(0, reader1);
				AssertReaderClosed(reader1, true, true);
				
				dir1.Close();
				dir2.Close();
			}
		}
예제 #16
0
        public virtual void  TestIncompatibleIndexes()
        {
            // two documents:
            Directory dir1 = GetDir1();
            
            // one document only:
            Directory dir2 = new MockRAMDirectory();
            IndexWriter w2 = new IndexWriter(dir2, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
            Document d3 = new Document();
            d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
            w2.AddDocument(d3);
            w2.Close();
            
            ParallelReader pr = new ParallelReader();
            pr.Add(IndexReader.Open(dir1, false));

            Assert.Throws<ArgumentException>(() => pr.Add(IndexReader.Open(dir2, false)),
                                                "didn't get exptected exception: indexes don't have same number of documents");
        }
        public virtual void  Test1()
        {
            ParallelReader pr = new ParallelReader();

            pr.Add(ir1);
            pr.Add(ir2);

            TermDocs td = pr.TermDocs();

            TermEnum te = pr.Terms();

            Assert.IsTrue(te.Next());
            Assert.AreEqual("field1:brown", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field1:fox", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field1:jumps", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field1:quick", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field1:the", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field2:brown", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field2:fox", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field2:jumps", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field2:quick", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field2:the", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:dog", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:fox", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:jumps", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:lazy", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:over", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsTrue(te.Next());
            Assert.AreEqual("field3:the", te.Term().ToString());
            td.Seek(te.Term());
            Assert.IsTrue(td.Next());
            Assert.AreEqual(0, td.Doc());
            Assert.IsFalse(td.Next());
            Assert.IsFalse(te.Next());
        }
예제 #18
0
		public virtual void  TestIsOptimized()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			
			// add another document to ensure that the indexes are not optimized
			IndexWriter modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			Document d = new Document();
			d.Add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
			modifier.AddDocument(d);
			modifier.Close();
			
			modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			d = new Document();
			d.Add(new Field("f2", "v2", Field.Store.YES, Field.Index.ANALYZED));
			modifier.AddDocument(d);
			modifier.Close();
			
			
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			Assert.IsFalse(pr.IsOptimized());
			pr.Close();
			
			modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			modifier.Optimize();
			modifier.Close();
			
			pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			// just one of the two indexes are optimized
			Assert.IsFalse(pr.IsOptimized());
			pr.Close();
			
			
			modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			modifier.Optimize();
			modifier.Close();
			
			pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			// now both indexes are optimized
			Assert.IsTrue(pr.IsOptimized());
			pr.Close();
		}
예제 #19
0
		public virtual void  TestIsCurrent()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			
			Assert.IsTrue(pr.IsCurrent());
			IndexReader modifier = IndexReader.Open(dir1);
			modifier.SetNorm(0, "f1", 100);
			modifier.Close();
			
			// one of the two IndexReaders which ParallelReader is using
			// is not current anymore
			Assert.IsFalse(pr.IsCurrent());
			
			modifier = IndexReader.Open(dir2);
			modifier.SetNorm(0, "f3", 100);
			modifier.Close();
			
			// now both are not current anymore
			Assert.IsFalse(pr.IsCurrent());
		}
예제 #20
0
		public virtual void  TestIncompatibleIndexes()
		{
			// two documents:
			Directory dir1 = GetDir1();
			
			// one document only:
			Directory dir2 = new MockRAMDirectory();
			IndexWriter w2 = new IndexWriter(dir2, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			Document d3 = new Document();
			d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
			w2.AddDocument(d3);
			w2.Close();
			
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			try
			{
				pr.Add(IndexReader.Open(dir2));
				Assert.Fail("didn't get exptected exception: indexes don't have same number of documents");
			}
			catch (System.ArgumentException e)
			{
				// expected exception
			}
		}
예제 #21
0
		public virtual void  TestDocument()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			
			Document doc11 = pr.Document(0, new MapFieldSelector(new System.String[]{"f1"}));
			Document doc24 = pr.Document(1, new MapFieldSelector(new System.Collections.ArrayList(new System.String[]{"f4"})));
			Document doc223 = pr.Document(1, new MapFieldSelector(new System.String[]{"f2", "f3"}));
			
			Assert.AreEqual(1, doc11.GetFields().Count);
			Assert.AreEqual(1, doc24.GetFields().Count);
			Assert.AreEqual(2, doc223.GetFields().Count);
			
			Assert.AreEqual("v1", doc11.Get("f1"));
			Assert.AreEqual("v2", doc24.Get("f4"));
			Assert.AreEqual("v2", doc223.Get("f2"));
			Assert.AreEqual("v2", doc223.Get("f3"));
		}
예제 #22
0
		public virtual void  TestAllTermDocs()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			int NUM_DOCS = 2;
			TermDocs td = pr.TermDocs(null);
			for (int i = 0; i < NUM_DOCS; i++)
			{
				Assert.IsTrue(td.Next());
				Assert.AreEqual(i, td.Doc());
				Assert.AreEqual(1, td.Freq());
			}
			td.Close();
			pr.Close();
			dir1.Close();
			dir2.Close();
		}
예제 #23
0
			protected internal override IndexReader OpenReader()
			{
				ParallelReader pr = new ParallelReader();
				pr.Add(IndexReader.Open(dir1));
				pr.Add(IndexReader.Open(dir2));
				MultiReader mr = new MultiReader(new IndexReader[]{IndexReader.Open(dir3), IndexReader.Open(dir4)});
				return new MultiReader(new IndexReader[]{pr, mr, IndexReader.Open(dir5)});
			}
예제 #24
0
		protected internal virtual IndexReader DoReopen(bool doClone)
		{
			EnsureOpen();
			
			bool reopened = false;
			System.Collections.IList newReaders = new System.Collections.ArrayList();
			
			bool success = false;
			
			try
			{
				for (int i = 0; i < readers.Count; i++)
				{
					IndexReader oldReader = (IndexReader) readers[i];
					IndexReader newReader = null;
					if (doClone)
					{
						newReader = (IndexReader) oldReader.Clone();
					}
					else
					{
						newReader = oldReader.Reopen();
					}
					newReaders.Add(newReader);
					// if at least one of the subreaders was updated we remember that
					// and return a new ParallelReader
					if (newReader != oldReader)
					{
						reopened = true;
					}
				}
				success = true;
			}
			finally
			{
				if (!success && reopened)
				{
					for (int i = 0; i < newReaders.Count; i++)
					{
						IndexReader r = (IndexReader) newReaders[i];
						if (r != readers[i])
						{
							try
							{
								r.Close();
							}
							catch (System.IO.IOException ignore)
							{
								// keep going - we want to clean up as much as possible
							}
						}
					}
				}
			}
			
			if (reopened)
			{
				System.Collections.IList newDecrefOnClose = new System.Collections.ArrayList();
				ParallelReader pr = new ParallelReader();
				for (int i = 0; i < readers.Count; i++)
				{
					IndexReader oldReader = (IndexReader) readers[i];
					IndexReader newReader = (IndexReader) newReaders[i];
					if (newReader == oldReader)
					{
						newDecrefOnClose.Add(true);
						newReader.IncRef();
					}
					else
					{
						// this is a new subreader instance, so on close() we don't
						// decRef but close it 
						newDecrefOnClose.Add(false);
					}
					pr.Add(newReader, !storedFieldReaders.Contains(oldReader));
				}
				pr.decrefOnClose = newDecrefOnClose;
				pr.incRefReaders = incRefReaders;
				return pr;
			}
			else
			{
				// No subreader was refreshed
				return this;
			}
		}
예제 #25
0
		// Fields 1 & 2 in one index, 3 & 4 in other, with ParallelReader:
		private Searcher Parallel()
		{
			Directory dir1 = GetDir1();
			Directory dir2 = GetDir2();
			ParallelReader pr = new ParallelReader();
			pr.Add(IndexReader.Open(dir1));
			pr.Add(IndexReader.Open(dir2));
			return new IndexSearcher(pr);
		}
예제 #26
0
        protected internal virtual IndexReader DoReopen(bool doClone)
        {
            EnsureOpen();

            bool reopened = false;

            System.Collections.IList newReaders = new System.Collections.ArrayList();

            bool success = false;

            try
            {
                for (int i = 0; i < readers.Count; i++)
                {
                    IndexReader oldReader = (IndexReader)readers[i];
                    IndexReader newReader = null;
                    if (doClone)
                    {
                        newReader = (IndexReader)oldReader.Clone();
                    }
                    else
                    {
                        newReader = oldReader.Reopen();
                    }
                    newReaders.Add(newReader);
                    // if at least one of the subreaders was updated we remember that
                    // and return a new ParallelReader
                    if (newReader != oldReader)
                    {
                        reopened = true;
                    }
                }
                success = true;
            }
            finally
            {
                if (!success && reopened)
                {
                    for (int i = 0; i < newReaders.Count; i++)
                    {
                        IndexReader r = (IndexReader)newReaders[i];
                        if (r != readers[i])
                        {
                            try
                            {
                                r.Close();
                            }
                            catch (System.IO.IOException ignore)
                            {
                                // keep going - we want to clean up as much as possible
                            }
                        }
                    }
                }
            }

            if (reopened)
            {
                System.Collections.IList newDecrefOnClose = new System.Collections.ArrayList();
                ParallelReader           pr = new ParallelReader();
                for (int i = 0; i < readers.Count; i++)
                {
                    IndexReader oldReader = (IndexReader)readers[i];
                    IndexReader newReader = (IndexReader)newReaders[i];
                    if (newReader == oldReader)
                    {
                        newDecrefOnClose.Add(true);
                        newReader.IncRef();
                    }
                    else
                    {
                        // this is a new subreader instance, so on close() we don't
                        // decRef but close it
                        newDecrefOnClose.Add(false);
                    }
                    pr.Add(newReader, !storedFieldReaders.Contains(oldReader));
                }
                pr.decrefOnClose = newDecrefOnClose;
                pr.incRefReaders = incRefReaders;
                return(pr);
            }
            else
            {
                // No subreader was refreshed
                return(this);
            }
        }
			protected internal override IndexReader OpenReader()
			{
				ParallelReader pr = new ParallelReader();
				pr.Add(IndexReader.Open(dir3));
				pr.Add(IndexReader.Open(dir4));
				pr.Add(new FilterIndexReader(IndexReader.Open(dir3)));
				return pr;
			}