Esempio n. 1
0
        public void CanRecordObjectWord()
        {
            string culture = "en-US";

            // Setup
            SearchObject s = new SearchObject();

            s.ObjectType = 0;
            s.ObjectId   = "1234";

            Lexicon lexicon = new Lexicon(new StaticLexicon());
            long    wordId  = lexicon.AddOrCreateWord("thi", culture);

            Assert.IsTrue(wordId > 0);

            Searcher searcher = new Searcher(lexicon, new StaticSearcher());
            long     id       = searcher.ObjectIndexAddOrUpdate(s);

            Assert.IsTrue(id > 0);

            // Test
            SearchObjectWord w = new SearchObjectWord();

            w.SearchObjectId = id;
            w.WordId         = wordId;
            w.Score          = 1;

            bool actual = searcher.ObjectWordIndexUpdate(w);

            Assert.IsTrue(actual);
        }
Esempio n. 2
0
        public void CanAddAWord()
        {
            string input   = "thi";
            string culture = "en-US";

            Lexicon lex = new Lexicon(new StaticLexicon());

            long id = lex.AddOrCreateWord(input, culture);

            Assert.IsTrue(id > 0);
        }
Esempio n. 3
0
        public void CanFindTwoWords()
        {
            string input   = "thi";
            string input2  = "test";
            string culture = "en-US";

            Lexicon lex      = new Lexicon(new StaticLexicon());
            long    expected = lex.AddOrCreateWord(input, culture);

            Assert.IsTrue(expected > 0);
            long expected2 = lex.AddOrCreateWord(input2, culture);

            Assert.IsTrue(expected2 > 0);

            long actual2 = lex.FindWordId(input2, culture);

            Assert.AreEqual(expected2, actual2);

            long actual = lex.FindWordId(input, culture);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void CanFindObjectsForWord()
        {
            long   siteId  = 0;
            string culture = "en-US";

            // Setup Words
            Lexicon lexicon  = new Lexicon(new StaticLexicon());
            long    thi_id   = lexicon.AddOrCreateWord("thi", culture);
            long    test_id  = lexicon.AddOrCreateWord("test", culture);
            long    sampl_id = lexicon.AddOrCreateWord("sampl", culture);

            // Setup Search Objects
            SearchObject s1 = new SearchObject();

            s1.ObjectType = 0;
            s1.ObjectId   = "1";
            SearchObject s2 = new SearchObject();

            s2.ObjectType = 0;
            s2.ObjectId   = "2";

            // Setup Searcher
            Searcher searcher = new Searcher(lexicon, new StaticSearcher());

            // Record Objects
            long sid1 = searcher.ObjectIndexAddOrUpdate(s1);
            long sid2 = searcher.ObjectIndexAddOrUpdate(s2);

            // Index Words for Objects
            SearchObjectWord w1_1 = new SearchObjectWord()
            {
                SearchObjectId = s1.Id, WordId = thi_id, Score = 1, SiteId = siteId
            };
            SearchObjectWord w1_2 = new SearchObjectWord()
            {
                SearchObjectId = s1.Id, WordId = test_id, Score = 1, SiteId = siteId
            };
            SearchObjectWord w2_1 = new SearchObjectWord()
            {
                SearchObjectId = s2.Id, WordId = thi_id, Score = 1, SiteId = siteId
            };
            SearchObjectWord w2_2 = new SearchObjectWord()
            {
                SearchObjectId = s2.Id, WordId = sampl_id, Score = 1, SiteId = siteId
            };

            searcher.ObjectWordIndexUpdate(w1_1);
            searcher.ObjectWordIndexUpdate(w1_2);
            searcher.ObjectWordIndexUpdate(w2_1);
            searcher.ObjectWordIndexUpdate(w2_2);

            // Test
            List <SearchObjectWord> actual = searcher.ObjectWordIndexFindByWordId(siteId, thi_id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Count);

            List <SearchObjectWord> actual2 = searcher.ObjectWordIndexFindByWordId(siteId, test_id);

            Assert.IsNotNull(actual2);
            Assert.AreEqual(1, actual2.Count);

            List <SearchObjectWord> actual3 = searcher.ObjectWordIndexFindByWordId(siteId, 99);

            Assert.IsNotNull(actual3);
            Assert.AreEqual(0, actual3.Count);
        }