Example #1
0
 /// <summary>Construct a SpanOrQuery merging the provided clauses. </summary>
 public SpanOrQuery(params SpanQuery[] clauses)
 {
     // copy clauses array into an ArrayList
     this.clauses = new Support.EquatableList <SpanQuery>(clauses.Length);
     for (int i = 0; i < clauses.Length; i++)
     {
         SpanQuery clause = clauses[i];
         if (i == 0)
         {
             // check field
             field = clause.GetField();
         }
         else if (!clause.GetField().Equals(field))
         {
             throw new System.ArgumentException("Clauses must have same field.");
         }
         this.clauses.Add(clause);
     }
 }
        public virtual void TestErrorInDocsWriterAdd()
        {

            MockRAMDirectory.Failure failure = new AnonymousClassFailure1(this);

            // create a couple of files

            System.String[] keywords = new System.String[] { "1", "2" };
            System.String[] unindexed = new System.String[] { "Netherlands", "Italy" };
            System.String[] unstored = new System.String[] { "Amsterdam has lots of bridges", "Venice has lots of canals" };
            System.String[] text = new System.String[] { "Amsterdam", "Venice" };

            for (int pass = 0; pass < 2; pass++)
            {
                bool autoCommit = (0 == pass);
                MockRAMDirectory dir = new MockRAMDirectory();
                IndexWriter modifier = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true);

                dir.FailOn(failure.Reset());

                for (int i = 0; i < keywords.Length; i++)
                {
                    Document doc = new Document();
                    doc.Add(new Field("id", keywords[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
                    doc.Add(new Field("country", unindexed[i], Field.Store.YES, Field.Index.NO));
                    doc.Add(new Field("contents", unstored[i], Field.Store.NO, Field.Index.ANALYZED));
                    doc.Add(new Field("city", text[i], Field.Store.YES, Field.Index.ANALYZED));
                    try
                    {
                        modifier.AddDocument(doc);
                    }
                    catch (System.IO.IOException io)
                    {
                        break;
                    }
                }

                Support.EquatableList<string> startFiles = new Support.EquatableList<string>(dir.ListAll());
                SegmentInfos infos = new SegmentInfos();
                infos.Read(dir);
                new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null, null);
                Support.EquatableList<string> endFiles = new Support.EquatableList<string>(dir.ListAll());

                if (!startFiles.Equals(endFiles))
                {
                    Assert.Fail("docswriter abort() failed to delete unreferenced files:\n  before delete:\n    " + startFiles.ToString() + "\n  after delete:\n    " + endFiles.ToString());
                }

                modifier.Close();
            }
        }