public void IncrementRanking_TestHalfLife()
        {
            string queryWordId  = "testId";
            string queryWordId2 = "testId2";

            string queryWord     = "testValue";
            double secondsToWait = 1;

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;
            long minAgo = DateTimeOffset.UtcNow.AddSeconds(-10).ToUnixTimeSeconds();

            double halfLife = secondsToWait / 3600;

            config.RankingProvider = new CurrentlyPopularRanking(minAgo, halfLife);

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord);

            wordSearch.BoostInRanking(queryWordId);
            wordSearch.BoostInRanking(queryWordId);

            Thread.Sleep((int)secondsToWait * 1000);

            wordSearch.BoostInRanking(queryWordId2);

            double?score1 = wordSearch.CurrentScore(queryWordId);
            double?score2 = wordSearch.CurrentScore(queryWordId2);

            Assert.IsTrue((score2 == score1) || (score2 == score1 * 2));
        }
        public void SearchResultFilter()
        {
            string queryWord  = "testValue";
            string queryWord2 = "testValue2";
            string queryWord3 = "testValue3";
            string searchWord = "test";

            string queryWordId  = "testId";
            string queryWordId2 = "testId2";
            string queryWordId3 = "testId3";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord2);
            wordSearch.Add(queryWordId3, queryWord3);

            Func <RedisValue, bool> filterFunc = value =>
            {
                if (value.Equals(queryWord))
                {
                    return(false);
                }
                return(true);
            };

            var results = wordSearch.Search(searchWord, filterFunc: filterFunc).AsStringList();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(queryWord, results[0]);
        }
        public void TopRankings()
        {
            string queryWordId  = "testId";
            string queryWordId2 = "testId2";

            string queryWord  = "testValue";
            string queryWord2 = "testValue2";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            config.RankingProvider = new CurrentlyPopularRanking(AppSettings.RANKING_EPOCH, 1);

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.BoostInRanking(queryWordId);

            wordSearch.Add(queryWordId2, queryWord2);
            wordSearch.BoostInRanking(queryWordId2);

            wordSearch.BoostInRanking(queryWordId);

            var words = wordSearch.TopRankedSearches().AsStringList();

            Assert.AreEqual(queryWord, words[0]);
            Assert.AreEqual(queryWord2, words[1]);
        }
Ejemplo n.º 4
0
        public void SearchSingle_Should_Get_Exception(string queryWord, string searchWord)
        {
            string          queryWordId  = "testId";
            string          queryWordId2 = "testId2";
            RedisWordSearch wordSearch   = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord);

            Assert.ThrowsException <System.InvalidOperationException>(() => wordSearch.SearchSingle(searchWord));
        }
Ejemplo n.º 5
0
        public void SearchableWord_AddUpdate_Data(string queryWord, string searchWord, string data)
        {
            string queryWordId = "testId";
            string dataSecond  = "testData2";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord, data);
            wordSearch.Add(queryWordId, queryWord, dataSecond);

            Assert.AreEqual(dataSecond, wordSearch.SearchSingle(searchWord).ToString());
        }
Ejemplo n.º 6
0
        public void SearchSingleOrDefault(string queryWord, string searchWord)
        {
            string queryWordId  = "testId";
            string queryWordId2 = "testId2";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);
            string          defValue   = "defualt";

            Assert.AreEqual(defValue, wordSearch.SearchSingleOrDefault(searchWord, defValue).ToString());

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord);
            Assert.AreEqual(defValue, wordSearch.SearchSingleOrDefault(searchWord, defValue).ToString());
        }
Ejemplo n.º 7
0
        public void MultipleSearchableWord(string queryWord, string searchWord)
        {
            string          queryWordId  = "testId";
            string          queryWordId2 = "testId2";
            RedisWordSearch wordSearch   = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord);

            var results = wordSearch.Search(searchWord).AsString().ToList();

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual(queryWord, results[0]);
            Assert.AreEqual(queryWord, results[1]);
        }
        public void Min_MaxSearchLengthLimit_SequentialCombination()
        {
            string queryWordId       = "testId";
            string queryWord         = "testValue";
            string searcWordCorrect  = "test";
            string searcWordCorrect2 = "estV";
            string searcWordCorrect3 = "tVal";
            string searcWordCorrect4 = "Valu";
            string searchWordEmpty   = "te";
            string searchWordEmpty2  = "testVal";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            config.MaxSearchLength    = 5;
            config.MinSearchLength    = 3;
            config.WordIndexingMethod = WordIndexing.SequentialCombination;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);

            Assert.AreEqual(1, wordSearch.Search(searcWordCorrect).Count());
            Assert.AreEqual(1, wordSearch.Search(searcWordCorrect2).Count());
            Assert.AreEqual(1, wordSearch.Search(searcWordCorrect3).Count());
            Assert.AreEqual(1, wordSearch.Search(searcWordCorrect4).Count());
            Assert.AreEqual(0, wordSearch.Search(searchWordEmpty).Count());
            Assert.AreEqual(0, wordSearch.Search(searchWordEmpty2).Count());
        }
Ejemplo n.º 9
0
        public void AddWord(string queryWord)
        {
            string queryWordId = "testId";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);

            Assert.IsTrue(wordSearch.Add(queryWordId, queryWord));
        }
Ejemplo n.º 10
0
        public void SearchSingle(string queryWord, string searchWord)
        {
            string queryWordId = "testId";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord);
            Assert.AreEqual(queryWord, wordSearch.SearchSingle(searchWord).ToString());
        }
        public void CaseInSensitiveConfiguration(string queryWord, string searchWord)
        {
            string queryWordId = "testId";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            config.IsCaseSensitive = false;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);

            Assert.AreEqual(queryWord, wordSearch.SearchSingle(searchWord).ToString());
            Assert.AreEqual(queryWord, wordSearch.SearchSingleOrDefault(searchWord.ToLower(), "default").ToString());

            wordSearch.Add(queryWordId.ToLower(), queryWord.ToLower(), "someData");
            Assert.AreEqual("someData", wordSearch.SearchSingle(searchWord).ToString());
        }
        public void Search_Sequential(string queryWord, string searchWord)
        {
            string queryWordId = "testId";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord);

            var results = wordSearch.Search(queryWord).AsStringList();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(queryWord, results[0]);
        }
        public void ResultLimit()
        {
            string queryWord  = "testValue";
            string queryWord2 = "testValue2";
            string queryWord3 = "testValue3";
            string searchWord = "test";

            string queryWordId  = "testId";
            string queryWordId2 = "testId2";
            string queryWordId3 = "testId3";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);
            wordSearch.Add(queryWordId2, queryWord2);
            wordSearch.Add(queryWordId3, queryWord3);

            Assert.AreEqual(3, wordSearch.Search(searchWord).Count());
            Assert.AreEqual(2, wordSearch.Search(searchWord, limit: 2).Count());
        }
Ejemplo n.º 14
0
        public void SearchableWord_AddRemove(string queryWord, string searchWord, string data)
        {
            string queryWordId = "testId";

            RedisWordSearch wordSearch = new RedisWordSearch(Database);

            wordSearch.Add(queryWordId, queryWord);

            Assert.AreEqual(queryWord, wordSearch.SearchSingle(searchWord).ToString());

            wordSearch.Remove(queryWordId);

            Assert.AreEqual(0, wordSearch.Search(searchWord).Count());
        }
        public void MaxSearchLengthLimit_EmptyResults(string queryWord, string searchWord)
        {
            string queryWordId = "testId";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            config.MaxSearchLength = 5;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);

            Assert.AreEqual(0, wordSearch.Search(searchWord).Count());
        }
        public void Search_SequentialCombination(string queryWord, string searchWord)
        {
            string queryWordId = "testId";

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;

            config.WordIndexingMethod = WordIndexing.SequentialCombination;

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);

            var results = wordSearch.Search(searchWord).AsStringList();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(queryWord, results[0]);
        }
        public void IncrementRanking()
        {
            string queryWordId     = "testId";
            string queryWord       = "testValue";
            int    halfLife        = 6;
            int    halfLifeSeconds = halfLife * 60 * 60;

            RedisWordSearchConfiguration config = RedisWordSearchConfiguration.defaultConfig;
            long epoch = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + (1074 * halfLifeSeconds);

            config.RankingProvider = new CurrentlyPopularRanking(epoch, halfLife);

            RedisWordSearch wordSearch = new RedisWordSearch(Database, config);

            wordSearch.Add(queryWordId, queryWord);

            wordSearch.BoostInRanking(queryWordId);
            Assert.AreNotEqual(0, wordSearch.CurrentScore(queryWordId));
        }