public void testWrite()
        {
            MemoryStream stream = new MemoryStream();
            CollectionMetadataWriter writer =
                new CollectionMetadataWriter(stream);

            DocumentInfo doc1 = new DocumentInfo("http://www.google.com/index.html", "Google", 150, "#Section1", null);
            DocumentInfo doc2 = new DocumentInfo("http://www.google.com/index.html", "Google", 250, "#Section2", null);
            writer.AddDocumentInfo(0, doc1);
            writer.AddDocumentInfo(1, doc2);
            writer.WriteOut();

            BinaryReader reader = new BinaryReader(stream);
            long collectionTokenCount = reader.ReadInt64();
            Assert.AreEqual(400, collectionTokenCount);

            FileIndex<long, DocumentInfo> documentIndex = new FileIndex<long, DocumentInfo>(
                new LongEncoder(), new DocumentInfoEncoder(), stream);
            Assert.AreEqual(2, documentIndex.EntryCount);

            DocumentInfo docInfo;
            Assert.IsTrue(documentIndex.TryGet(0, out docInfo));
            Assert.AreEqual(doc1, docInfo);

            Assert.IsTrue(documentIndex.TryGet(1, out docInfo));
            Assert.AreEqual(doc2, docInfo);
        }
Example #2
0
        public void before()
        {
            MemoryStream termIndexStream = new MemoryStream();
            using (FileIndexWriter<string, IList<Posting>> indexWriter = new FileIndexWriter<string, IList<Posting>>(
                new StringEncoder(), new PostingListEncoder(), termIndexStream))
            {
                this.postingsWithBar = new List<Posting>();
                postingsWithBar.Add(new Posting(0, 1));
                postingsWithBar.Add(new Posting(1, 2));
                indexWriter.Add("bar", postingsWithBar);

                this.postingsWithFoo = new List<Posting>();
                postingsWithFoo.Add(new Posting(0, 4));
                indexWriter.Add("foo", postingsWithFoo);

                indexWriter.WriteOut();
            }
            this.index = new TermIndex(termIndexStream);

            MemoryStream metadataStream = new MemoryStream();
            using (CollectionMetadataWriter metadataWriter = new CollectionMetadataWriter(metadataStream))
            {
                metadataWriter.AddDocumentInfo(0, new DocumentInfo("http://www.example.com/index.html", "Example", 100, "", null));
                metadataWriter.AddDocumentInfo(1, new DocumentInfo("http://www.example.com/menu.html", "Example", 300, "", null));
                metadataWriter.WriteOut();
            }

            this.metadata = new IndexMetadata(metadataStream);
        }
Example #3
0
 public SpimiIndexer(ILexer lexer, IParser parser, Stream indexStream, Stream metadata)
 {
     this.lexer = lexer;
     this.parser = parser;
     this.termIndexBlockWriter = new SpimiBlockWriter();
     this.indexStream = indexStream;
     this.metadataWriter = new CollectionMetadataWriter(metadata);
 }