示例#1
0
        public void Constructor()
        {
            IInMemoryIndex index  = MockInMemoryIndex();
            IndexStorer    storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);

            Assert.AreEqual(index, storer.Index, "Wrong index");
        }
示例#2
0
        public void DataCorrupted()
        {
            IInMemoryIndex index = MockInMemoryIndex();
            IDocument      doc1  = MockDocument("doc1", "Document", "doc", DateTime.Now);
            IDocument      doc2  = MockDocument2("doc2", "Article", "doc", DateTime.Now);

            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return(d.Name == doc1.Name ? doc1 : doc2); });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);

            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            index.StoreDocument(doc2, null, "", null);

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            storer.Dispose();
            storer = null;

            File.Create(documentsFile).Close();

            index = MockInMemoryIndex();

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.IsTrue(storer.DataCorrupted, "DataCorrupted should be true");
            Assert.AreEqual(0, index.TotalDocuments, "Wrong document count");
        }
示例#3
0
        public void ReplaceDocument()
        {
            // This test checks that IndexStorer properly discards the old document when a new copy is stored,
            // even when the title and date/time are different

            IInMemoryIndex index = MockInMemoryIndex();
            DateTime       dt1   = DateTime.Now.AddDays(-1);
            IDocument      doc1  = MockDocument("doc1", "Document", "doc", dt1);
            IDocument      doc2  = MockDocument2("doc1", "Article", "doc", DateTime.Now);

            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return(d.DateTime == dt1 ? doc1 : doc2); });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);

            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
            index.StoreDocument(doc2, null, "", null);
            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return(d.DateTime == dt1 ? doc1 : doc2); });

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
        }
示例#4
0
        public void DataCorrupted()
        {
            IInMemoryIndex index = MockInMemoryIndex();
            IDocument doc1 = MockDocument("doc1", "Document", "doc", DateTime.Now);
            IDocument doc2 = MockDocument2("doc2", "Article", "doc", DateTime.Now);
            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return d.Name == doc1.Name ? doc1 : doc2; });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            index.StoreDocument(doc2, null, "", null);

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            storer.Dispose();
            storer = null;

            File.Create(documentsFile).Close();

            index = MockInMemoryIndex();

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.IsTrue(storer.DataCorrupted, "DataCorrupted should be true");
            Assert.AreEqual(0, index.TotalDocuments, "Wrong document count");
        }
示例#5
0
 public void Constructor_NullIndex()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, null);
     });
 }
示例#6
0
 public void Constructor_InvalidMappingsFile_ShouldThrowArgumentException(string file)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         IndexStorer storer = new IndexStorer(documentsFile, wordsFile, file, MockInMemoryIndex());
     });
 }
示例#7
0
        public void Size()
        {
            IInMemoryIndex index = MockInMemoryIndex();

            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return(null); });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);

            storer.LoadIndex();

            Assert.IsTrue(storer.Size > 0, "Size should be greater than zero");
        }
示例#8
0
        public void LoadIndexAndModifications()
        {
            IInMemoryIndex index = MockInMemoryIndex();
            IDocument      doc1  = MockDocument("doc1", "Document", "doc", DateTime.Now);
            IDocument      doc2  = MockDocument2("doc2", "Article", "doc", DateTime.Now);

            BuildDocument buildDoc = new BuildDocument(delegate(DumpedDocument d) {
                return(d.Name == doc1.Name ? doc1 : doc2);
            });

            index.SetBuildDocumentDelegate(buildDoc);

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);

            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            index.StoreDocument(doc2, null, "", null);

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            SearchResultCollection res = index.Search(new SearchParameters("document content article"));

            Assert.AreEqual(2, res.Count, "Wrong result count");
            Assert.AreEqual(2, res[0].Matches.Count, "Wrong matches count");
            Assert.AreEqual(1, res[1].Matches.Count, "Wrong matches count");

            Assert.AreEqual("document", res[0].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location");

            Assert.AreEqual("content", res[0].Matches[1].Text, "Wrong match text");
            Assert.AreEqual(13, res[0].Matches[1].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(3, res[0].Matches[1].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Content, res[0].Matches[1].Location, "Wrong match location");

            Assert.AreEqual("article", res[1].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[1].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[1].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[1].Matches[0].Location, "Wrong match location");

            index.RemoveDocument(doc1, null);

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(7, index.TotalWords, "Wrong word count");
            Assert.AreEqual(7, index.TotalOccurrences, "Wrong occurrence count");

            res = index.Search(new SearchParameters("document content article"));
            Assert.AreEqual(1, res.Count, "Wrong result count");
            Assert.AreEqual(1, res[0].Matches.Count, "Wrong matches count");

            Assert.AreEqual("article", res[0].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location");

            index.Clear(null);

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(0, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(0, index.TotalWords, "Wrong word count");
            Assert.AreEqual(0, index.TotalOccurrences, "Wrong occurrence count");
            Assert.AreEqual(0, index.Search(new SearchParameters("document")).Count, "Wrong result count");
        }
示例#9
0
 public void Constructor_NullIndex()
 {
     IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, null);
 }
示例#10
0
 public void Constructor_InvalidMappingsFile(string file)
 {
     IndexStorer storer = new IndexStorer(documentsFile, wordsFile, file, MockInMemoryIndex());
 }
示例#11
0
        public void LoadIndexAndModifications()
        {
            IInMemoryIndex index = MockInMemoryIndex();
            IDocument doc1 = MockDocument("doc1", "Document", "doc", DateTime.Now);
            IDocument doc2 = MockDocument2("doc2", "Article", "doc", DateTime.Now);

            BuildDocument buildDoc = new BuildDocument(delegate(DumpedDocument d) {
                return d.Name == doc1.Name ? doc1 : doc2;
            });

            index.SetBuildDocumentDelegate(buildDoc);

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            index.StoreDocument(doc2, null, "", null);

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(2, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(12, index.TotalWords, "Wrong word count");
            Assert.AreEqual(12, index.TotalOccurrences, "Wrong occurrence count");

            SearchResultCollection res = index.Search(new SearchParameters("document content article"));
            Assert.AreEqual(2, res.Count, "Wrong result count");
            Assert.AreEqual(2, res[0].Matches.Count, "Wrong matches count");
            Assert.AreEqual(1, res[1].Matches.Count, "Wrong matches count");

            Assert.AreEqual("document", res[0].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location");

            Assert.AreEqual("content", res[0].Matches[1].Text, "Wrong match text");
            Assert.AreEqual(13, res[0].Matches[1].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(3, res[0].Matches[1].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Content, res[0].Matches[1].Location, "Wrong match location");

            Assert.AreEqual("article", res[1].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[1].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[1].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[1].Matches[0].Location, "Wrong match location");

            index.RemoveDocument(doc1, null);

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(7, index.TotalWords, "Wrong word count");
            Assert.AreEqual(7, index.TotalOccurrences, "Wrong occurrence count");

            res = index.Search(new SearchParameters("document content article"));
            Assert.AreEqual(1, res.Count, "Wrong result count");
            Assert.AreEqual(1, res[0].Matches.Count, "Wrong matches count");

            Assert.AreEqual("article", res[0].Matches[0].Text, "Wrong match text");
            Assert.AreEqual(0, res[0].Matches[0].FirstCharIndex, "Wrong match first char index");
            Assert.AreEqual(0, res[0].Matches[0].WordIndex, "Wrong match word index");
            Assert.AreEqual(WordLocation.Title, res[0].Matches[0].Location, "Wrong match location");

            index.Clear(null);

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(buildDoc);

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(0, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(0, index.TotalWords, "Wrong word count");
            Assert.AreEqual(0, index.TotalOccurrences, "Wrong occurrence count");
            Assert.AreEqual(0, index.Search(new SearchParameters("document")).Count, "Wrong result count");
        }
示例#12
0
 public void Constructor_NullIndex()
 {
     IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, null);
 }
示例#13
0
 public void Constructor_InvalidWordsFile(string file)
 {
     IndexStorer storer = new IndexStorer(documentsFile, file, mappingsFile, MockInMemoryIndex());
 }
示例#14
0
 public void Constructor()
 {
     IInMemoryIndex index = MockInMemoryIndex();
     IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
     Assert.AreEqual(index, storer.Index, "Wrong index");
 }
示例#15
0
        public void Size()
        {
            IInMemoryIndex index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return null; });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.IsTrue(storer.Size > 0, "Size should be greater than zero");
        }
示例#16
0
        public void ReplaceDocument()
        {
            // This test checks that IndexStorer properly discards the old document when a new copy is stored,
            // even when the title and date/time are different

            IInMemoryIndex index = MockInMemoryIndex();
            DateTime dt1 = DateTime.Now.AddDays(-1);
            IDocument doc1 = MockDocument("doc1", "Document", "doc", dt1);
            IDocument doc2 = MockDocument2("doc1", "Article", "doc", DateTime.Now);
            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return d.DateTime == dt1 ? doc1 : doc2; });

            IndexStorer storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            index.StoreDocument(doc1, null, "", null);
            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
            index.StoreDocument(doc2, null, "", null);
            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");

            storer.Dispose();
            storer = null;

            index = MockInMemoryIndex();
            index.SetBuildDocumentDelegate(delegate(DumpedDocument d) { return d.DateTime == dt1 ? doc1 : doc2; });

            storer = new IndexStorer(documentsFile, wordsFile, mappingsFile, index);
            storer.LoadIndex();

            Assert.AreEqual(1, index.TotalDocuments, "Wrong document count");
        }