Exemple #1
0
        public void Can_append()
        {
            const string fileName = "c:\\temp\\resin_tests\\FieldFileTests\\Can_append\\0.fld";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (var writer = new FieldFile(fileName))
            {
                writer.Write(0, "Hello", 0);
            }

            var terms = FieldReader.Load(fileName).GetAllTokens();

            Assert.AreEqual(1, terms.Count);
            Assert.IsTrue(terms.Contains("Hello"));
            Assert.IsFalse(terms.Contains("World!"));

            using (var writer = new FieldFile(fileName))
            {
                writer.Write(0, "World!", 1);
            }

            terms = FieldReader.Load(fileName).GetAllTokens();

            Assert.AreEqual(2, terms.Count);
            Assert.IsTrue(terms.Contains("Hello"));
            Assert.IsTrue(terms.Contains("World!"));
        }
Exemple #2
0
        public void Can_read_field_file()
        {
            const string fileName = "c:\\temp\\resin_tests\\Can_read_field_file\\0.fld";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            using (var fw = new FieldFile(fileName))
            {
                fw.Write(0, "hello", 0);
                fw.Write(5, "world", 1);
            }
            var reader = FieldReader.Load(fileName);
            var helloPositionsForDocId0 = reader.GetPostings("hello")[0];
            var worldPositionsForDocId5 = reader.GetPostings("world")[5];

            Assert.AreEqual(0, helloPositionsForDocId0.First());
            Assert.AreEqual(1, worldPositionsForDocId5.First());
        }
Exemple #3
0
        public void Can_read_write()
        {
            const string fileName = "c:\\temp\\resin_tests\\FieldFileTests\\Can_read_write\\0.fld";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            using (var writer = new FieldFile(fileName))
            {
                writer.Write(0, "Hello", 0);
                writer.Write(0, "World!", 1);
            }

            Assert.IsTrue(File.Exists(fileName));

            var reader = FieldReader.Load(fileName);
            var terms  = reader.GetAllTokens();

            Assert.IsTrue(terms.Contains("Hello"));
            Assert.IsTrue(terms.Contains("World!"));
        }