示例#1
0
        private void DoAssert(Documents.Document doc, bool fromIndex)
        {
            IndexableField[] keywordFieldValues = doc.GetFields("keyword");
            IndexableField[] textFieldValues = doc.GetFields("text");
            IndexableField[] unindexedFieldValues = doc.GetFields("unindexed");
            IndexableField[] unstoredFieldValues = doc.GetFields("unstored");

            Assert.IsTrue(keywordFieldValues.Length == 2);
            Assert.IsTrue(textFieldValues.Length == 2);
            Assert.IsTrue(unindexedFieldValues.Length == 2);
            // this test cannot work for documents retrieved from the index
            // since unstored fields will obviously not be returned
            if (!fromIndex)
            {
                Assert.IsTrue(unstoredFieldValues.Length == 2);
            }

            Assert.IsTrue(keywordFieldValues[0].StringValue.Equals("test1"));
            Assert.IsTrue(keywordFieldValues[1].StringValue.Equals("test2"));
            Assert.IsTrue(textFieldValues[0].StringValue.Equals("test1"));
            Assert.IsTrue(textFieldValues[1].StringValue.Equals("test2"));
            Assert.IsTrue(unindexedFieldValues[0].StringValue.Equals("test1"));
            Assert.IsTrue(unindexedFieldValues[1].StringValue.Equals("test2"));
            // this test cannot work for documents retrieved from the index
            // since unstored fields will obviously not be returned
            if (!fromIndex)
            {
                Assert.IsTrue(unstoredFieldValues[0].StringValue.Equals("test1"));
                Assert.IsTrue(unstoredFieldValues[1].StringValue.Equals("test2"));
            }
        }