Esempio n. 1
0
        public virtual void  TestRemoveForNewDocument()
        {
            Document doc = MakeDocumentWithFields();

            Assert.AreEqual(8, doc.fields_ForNUnit.Count);
            doc.RemoveFields("keyword");
            Assert.AreEqual(6, doc.fields_ForNUnit.Count);
            doc.RemoveFields("doesnotexists");       // removing non-existing fields is siltenlty ignored
            doc.RemoveFields("keyword");             // removing a field more than once
            Assert.AreEqual(6, doc.fields_ForNUnit.Count);
            doc.RemoveField("text");
            Assert.AreEqual(5, doc.fields_ForNUnit.Count);
            doc.RemoveField("text");
            Assert.AreEqual(4, doc.fields_ForNUnit.Count);
            doc.RemoveField("text");
            Assert.AreEqual(4, doc.fields_ForNUnit.Count);
            doc.RemoveField("doesnotexists");             // removing non-existing fields is siltenlty ignored
            Assert.AreEqual(4, doc.fields_ForNUnit.Count);
            doc.RemoveFields("unindexed");
            Assert.AreEqual(2, doc.fields_ForNUnit.Count);
            doc.RemoveFields("unstored");
            Assert.AreEqual(0, doc.fields_ForNUnit.Count);
            doc.RemoveFields("doesnotexists");             // removing non-existing fields is siltenlty ignored
            Assert.AreEqual(0, doc.fields_ForNUnit.Count);
        }
Esempio n. 2
0
        public virtual void  TestBinaryField()
        {
            Document  doc        = new Document();
            Fieldable stringFld  = new Field("string", binaryVal, Field.Store.YES, Field.Index.NO);
            Fieldable binaryFld  = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal), Field.Store.YES);
            Fieldable binaryFld2 = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal2), Field.Store.YES);

            doc.Add(stringFld);
            doc.Add(binaryFld);

            Assert.AreEqual(2, doc.fields_ForNUnit.Count);

            Assert.IsTrue(binaryFld.IsBinary());
            Assert.IsTrue(binaryFld.IsStored());
            Assert.IsFalse(binaryFld.IsIndexed());
            Assert.IsFalse(binaryFld.IsTokenized());

            System.String binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(doc.GetBinaryValue("binary")));
            Assert.IsTrue(binaryTest.Equals(binaryVal));

            System.String stringTest = doc.Get("string");
            Assert.IsTrue(binaryTest.Equals(stringTest));

            doc.Add(binaryFld2);

            Assert.AreEqual(3, doc.fields_ForNUnit.Count);

            byte[][] binaryTests = doc.GetBinaryValues("binary");

            Assert.AreEqual(2, binaryTests.Length);

            binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[0]));
            System.String binaryTest2 = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[1]));

            Assert.IsFalse(binaryTest.Equals(binaryTest2));

            Assert.IsTrue(binaryTest.Equals(binaryVal));
            Assert.IsTrue(binaryTest2.Equals(binaryVal2));

            doc.RemoveField("string");
            Assert.AreEqual(2, doc.fields_ForNUnit.Count);

            doc.RemoveFields("binary");
            Assert.AreEqual(0, doc.fields_ForNUnit.Count);
        }
Esempio n. 3
0
        public static void PopulateDocument(Document doc, IEnumerable<IFacetHandler> handlers)
        {
            StringBuilder tokenBuffer = new StringBuilder();

            foreach (var handler in handlers)
            {
                string name = handler.Name;
                string[] values = doc.GetValues(name);
                if (values != null)
                {
                    doc.RemoveFields(name);
                    foreach (string value in values)
                    {
                        doc.Add(new Field(name, value, Field.Store.NO, Field.Index.NOT_ANALYZED));
                        tokenBuffer.Append(' ').Append(value);
                    }
                }
            }
        }
        public static void PopulateDocument(Document doc, FieldConfiguration fConf)
        {
            var fields = fConf.GetFieldNames();

            var tokenBuffer = new StringBuilder();

            for (int i = 0; i < fields.Length; ++i)
            {
                var values = doc.GetValues(fields[i]);
                if (values != null)
                {
                    doc.RemoveFields(fields[i]);
                    for (int k = 0; k < values.Length; ++k)
                    {
                        doc.Add(new Field(fields[i], values[i], Field.Store.NO, Field.Index.NOT_ANALYZED));
                        tokenBuffer.Append(" ").Append(values[i]);
                    }
                }
            }
        }
Esempio n. 5
0
		public virtual void  TestBinaryField()
		{
			Document doc = new Document();
			Fieldable stringFld = new Field("string", binaryVal, Field.Store.YES, Field.Index.NO);
			Fieldable binaryFld = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal), Field.Store.YES);
			Fieldable binaryFld2 = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal2), Field.Store.YES);
			
			doc.Add(stringFld);
			doc.Add(binaryFld);
			
			Assert.AreEqual(2, doc.fields_ForNUnit.Count);
			
			Assert.IsTrue(binaryFld.IsBinary());
			Assert.IsTrue(binaryFld.IsStored());
			Assert.IsFalse(binaryFld.IsIndexed());
			Assert.IsFalse(binaryFld.IsTokenized());
			
			System.String binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(doc.GetBinaryValue("binary")));
			Assert.IsTrue(binaryTest.Equals(binaryVal));
			
			System.String stringTest = doc.Get("string");
			Assert.IsTrue(binaryTest.Equals(stringTest));
			
			doc.Add(binaryFld2);
			
			Assert.AreEqual(3, doc.fields_ForNUnit.Count);
			
			byte[][] binaryTests = doc.GetBinaryValues("binary");
			
			Assert.AreEqual(2, binaryTests.Length);
			
			binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[0]));
			System.String binaryTest2 = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[1]));
			
			Assert.IsFalse(binaryTest.Equals(binaryTest2));
			
			Assert.IsTrue(binaryTest.Equals(binaryVal));
			Assert.IsTrue(binaryTest2.Equals(binaryVal2));
			
			doc.RemoveField("string");
			Assert.AreEqual(2, doc.fields_ForNUnit.Count);
			
			doc.RemoveFields("binary");
			Assert.AreEqual(0, doc.fields_ForNUnit.Count);
		}
Esempio n. 6
0
                // Add a new field with whitespace separated names of the existing fields
                static protected void AddFieldProperies (Document doc)
                {
                        const string Separator = " ";

                        StringBuilder sb = new StringBuilder ();
                        bool seen_properties = false;

                        foreach (Fieldable f in doc.Fields ()) {
                                if (f.Name () == "Properties") {
                                        seen_properties = true;
                                        continue;
                                }

                                sb.Append (f.Name ());
                                sb.Append (Separator);
                        }

                        if (sb.Length > 0)
                                sb.Length -= Separator.Length;

                        if (seen_properties)
                                doc.RemoveFields ("Properties");

                        Field field = new Field ("Properties", sb.ToString (), Field.Store.NO, Field.Index.TOKENIZED);
                        doc.Add (field);
                }