public void CanSearchSeparateSites() { long siteId = 99; long siteId2 = 1; string culture = "en-US"; // Setup Objects Lexicon l = new Lexicon(new StaticLexicon()); Searcher s = new Searcher(l, new StaticSearcher()); SimpleTextIndexer indexer = new SimpleTextIndexer(s); indexer.Index(siteId, "1", 0, "Document Red", "Red is the first document. Red is a test.", culture); indexer.Index(siteId, "2", 0, "Document Blue", "Blue is the second document not Red like the first. Blue document is a sample", culture); indexer.Index(siteId, "3", 0, "Shakespeare: Julius Ceasar", "Et tu brute?", culture); indexer.Index(siteId2, "4", 0, "Shakespeare: To Be or Not To Be", "To be or not to be", culture); indexer.Index(siteId2, "5", 0, "Doc Brown", "The Flux Capacitor is what enables time travel. I fell off my toilet and hit my head. When I woke up, I drew this...", culture); string query = "Shakespeare"; int total = 0; List <SearchObject> results = s.DoSearch(siteId, query, culture, 1, 10, ref total); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); Assert.AreEqual("3", results[0].ObjectId); List <SearchObject> results2 = s.DoSearch(siteId2, query, culture, 1, 10, ref total); Assert.IsNotNull(results2); Assert.AreEqual(1, results2.Count); Assert.AreEqual("4", results2[0].ObjectId); }
public void CanScoreDocumentsSearch() { long siteId = 0; string culture = "en-US"; // Setup Objects Lexicon l = new Lexicon(new StaticLexicon()); Searcher s = new Searcher(l, new StaticSearcher()); SimpleTextIndexer indexer = new SimpleTextIndexer(s); indexer.Index(siteId, "1", 0, "Document Red", "Red is the first document. Red is a test.", culture); indexer.Index(siteId, "2", 0, "Document Blue", "Blue is the second document not Red like the first. Blue Blue document is a sample", culture); indexer.Index(siteId, "3", 0, "Shakespeare: Julius Ceasar", "Et tu brute?", culture); indexer.Index(siteId, "4", 0, "Shakespeare: To Be or Not To Be", "To be or not to be document Red Red Red Red Red Red Red", culture); indexer.Index(siteId, "5", 0, "Doc Brown", "The Flux Capacitor is what enables time travel. I fell off my toilet and hit my head. When I woke up, I drew this...", culture); string query = "document red"; int total = 0; List <SearchObject> results = s.DoSearch(query, 1, 10, culture, ref total); Assert.IsNotNull(results); Assert.AreEqual(3, results.Count); Assert.AreEqual(4, results[0].Id, "First Document should be #4"); Assert.AreEqual(1, results[1].Id, "Second Document should be #1"); Assert.AreEqual(2, results[2].Id, "Last Document should be #2"); }
public void CanIndexAnObject() { string culture = "en-US"; string message = "Red is a sample or red is a test."; Lexicon l = new Lexicon(new StaticLexicon()); Searcher s = new Searcher(l, new StaticSearcher()); SimpleTextIndexer indexer = new SimpleTextIndexer(s); indexer.Index(0, "1234", 0, "", message, culture); SearchObject actual = s.ObjectIndexFindByTypeAndId(0, 0, "1234"); Assert.IsNotNull(actual); List <SearchObjectWord> words = s.ObjectWordIndexFindAll(); Assert.IsNotNull(words); List <SearchObjectWord> expected = new List <SearchObjectWord>(); expected.Add(new SearchObjectWord() { SearchObjectId = actual.Id, WordId = l.FindWordId("red", culture), Score = 2 }); expected.Add(new SearchObjectWord() { SearchObjectId = actual.Id, WordId = l.FindWordId("sampl", culture), Score = 1 }); expected.Add(new SearchObjectWord() { SearchObjectId = actual.Id, WordId = l.FindWordId("test", culture), Score = 1 }); Assert.AreEqual(expected.Count, words.Count); Assert.AreEqual(expected[0].WordId, words[0].WordId); Assert.AreEqual(expected[1].WordId, words[1].WordId); Assert.AreEqual(expected[2].WordId, words[2].WordId); Assert.AreEqual(expected[0].Score, words[0].Score); Assert.AreEqual(expected[1].Score, words[1].Score); Assert.AreEqual(expected[2].Score, words[2].Score); }