Пример #1
0
    def test_xlarge_data_set_of_records_and_a_few_recommendations(self):
        records_to_test = range(0, 1000000)
        recommendations = {}

        for recid in records_to_test[0:1000]:
            recommendations[recid] = random()

        self.redis.set("obelix::recommendations::1", json.dumps(recommendations))

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)

        self.assertNotEquals(records_to_test[0:100], s1.rank()[0][0:100])
        self.assertNotEquals(records_to_test[0:3], s1.rank()[0][0:3])
Пример #2
0
    def test_xlarge_data_set_of_records_and_a_few_recommendations(self):
        records_to_test = range(0, 1000000)
        recommendations = {}

        for recid in records_to_test[0:1000]:
            recommendations[recid] = random()

        self.redis.set("obelix::recommendations::1",
                       json.dumps(recommendations))

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)

        self.assertNotEquals(records_to_test[0:100], s1.rank()[0][0:100])
        self.assertNotEquals(records_to_test[0:3], s1.rank()[0][0:3])
Пример #3
0
    def test_different_users_get_same_results_with_same_recommendations(self):
        hitset = [1, 2, 3, 4, 5]

        self.redis.set("obelix::recommendations::1", json.dumps({1: 0.9, 2: 0.5}))
        self.redis.set("obelix::recommendations::2", json.dumps({1: 0.9, 2: 0.5}))

        s1 = ObelixSearchEngine("1", hitset, redis=self.redis)
        s2 = ObelixSearchEngine("2", hitset, redis=self.redis)

        s1_records, s1_scores = s1.rank()
        s2_records, s2_scores = s2.rank()

        self.assertEquals(s1_records, s2_records)
        self.assertEquals(s1_scores, s2_scores)
Пример #4
0
    def test_ranked_scores_by_order_only_one_result(self):
        hitset = [1]

        ranker = ObelixSearchEngine('1', hitset)
        records, scores = ranker.rank()

        self.assertEquals(records, [1])
Пример #5
0
    def test_large_data_set_of_records(self):
        records_to_test = range(0, 50000)

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)
        jrec, rg = 0, 10

        self.assertEquals(records_to_test[jrec:jrec + rg], s1.rank()[0][jrec:jrec + rg])
Пример #6
0
    def test_ranked_scores_by_order_only_one_result(self):
        hitset = [1]

        ranker = ObelixSearchEngine('1', hitset)
        records, scores = ranker.rank()

        self.assertEquals(records, [1])
Пример #7
0
    def test_large_data_set_of_records(self):
        records_to_test = range(0, 50000)

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)
        jrec, rg = 0, 10

        self.assertEquals(records_to_test[jrec:jrec + rg],
                          s1.rank()[0][jrec:jrec + rg])
Пример #8
0
    def testrank_records_obelix_using_ip_as_userid(self):
        user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"}
        hitset = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        uid = user_info['remote_ip']

        ranker = ObelixSearchEngine(uid, hitset)
        records, scores = ranker.rank()
        self.assertEqual(hitset, records)

        ObelixSearchEngineLogger(self.redis).page_view(user_info, uid)
Пример #9
0
    def testrank_records_obelix_using_ip_as_userid(self):
        user_info = {'uid': 1, 'remote_ip': "127.0.0.1", "uri": "testuri"}
        hitset = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        uid = user_info['remote_ip']

        ranker = ObelixSearchEngine(uid, hitset)
        records, scores = ranker.rank()
        self.assertEqual(hitset, records)

        ObelixSearchEngineLogger(self.redis).page_view(user_info, uid)
Пример #10
0
    def test_large_dataset_find_hidden_treasure(self):
        records_to_test = range(0, 1000000)

        recommendations = {1: 0.9, 90000: 1.0, 430: 0.8}

        self.redis.set("obelix::recommendations::1", json.dumps(recommendations))

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)
        s1records, s2scores = s1.rank()

        for key, val in recommendations.iteritems():
            self.assertTrue(key in s1records)
Пример #11
0
    def test_large_dataset_find_hidden_treasure(self):
        records_to_test = range(0, 1000000)

        recommendations = {1: 0.9, 90000: 1.0, 430: 0.8}

        self.redis.set("obelix::recommendations::1",
                       json.dumps(recommendations))

        s1 = ObelixSearchEngine("1", records_to_test, redis=self.redis)
        s1records, s2scores = s1.rank()

        for key, val in recommendations.iteritems():
            self.assertTrue(key in s1records)
Пример #12
0
    def test_different_users_get_same_results_with_same_recommendations(self):
        hitset = [1, 2, 3, 4, 5]

        self.redis.set("obelix::recommendations::1",
                       json.dumps({
                           1: 0.9,
                           2: 0.5
                       }))
        self.redis.set("obelix::recommendations::2",
                       json.dumps({
                           1: 0.9,
                           2: 0.5
                       }))

        s1 = ObelixSearchEngine("1", hitset, redis=self.redis)
        s2 = ObelixSearchEngine("2", hitset, redis=self.redis)

        s1_records, s1_scores = s1.rank()
        s2_records, s2_scores = s2.rank()

        self.assertEquals(s1_records, s2_records)
        self.assertEquals(s1_scores, s2_scores)