Ejemplo n.º 1
0
    def test_set_recommendation_impact_via_redis(self):

        user_info = {'uid': '1', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        records_to_test = range(0, 100000)
        recommendations = {90000: 1.0, 4300: 0.3}

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

        settings = ObelixSearchEngineSettings(redis=self.redis)
        settings_json = settings.dump()

        settings_json['recommendations_impact'] = 1
        self.redis.set("obelix::settings", json.dumps(settings_json))

        records, scores = rank_records_obelix(user_info,
                                              records_to_test,
                                              rg=10,
                                              jrec=0,
                                              settings=settings)

        for key, val in recommendations.iteritems():
            self.assertTrue(key in records)

        settings_json['recommendations_impact'] = 0.1
        self.redis.set("obelix::settings", json.dumps(settings_json))

        records, scores = rank_records_obelix(user_info,
                                              records_to_test,
                                              rg=10,
                                              jrec=0,
                                              settings=settings)
        for key, val in recommendations.iteritems():
            self.assertFalse(key in records)
Ejemplo n.º 2
0
    def test_set_recommendation_impact_via_redis(self):

        user_info = {'uid': '1', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        records_to_test = range(0, 100000)
        recommendations = {90000: 1.0, 4300: 0.3}

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

        settings = ObelixSearchEngineSettings(redis=self.redis)
        settings_json = settings.dump()

        settings_json['recommendations_impact'] = 1
        self.redis.set("obelix::settings", json.dumps(settings_json))

        records, scores = rank_records_obelix(user_info,
                                               records_to_test,
                                               rg=10, jrec=0,
                                               settings=settings)

        for key, val in recommendations.iteritems():
            self.assertTrue(key in records)

        settings_json['recommendations_impact'] = 0.1
        self.redis.set("obelix::settings", json.dumps(settings_json))

        records, scores = rank_records_obelix(user_info,
                                               records_to_test,
                                               rg=10, jrec=0,
                                               settings=settings)
        for key, val in recommendations.iteritems():
            self.assertFalse(key in records)
Ejemplo n.º 3
0
    def test_large_dataset_hidden_treasure_lost_without_recommendations(self):

        user_info = {'uid': '1', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        records_to_test = range(0, 100000)
        recommendations = {90000: 1.0, 430: 0.8}

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

        settings = ObelixSearchEngineSettings(redis=self.redis)
        settings.recommendations_impact = 0

        records, scores = rank_records_obelix(user_info,
                                               records_to_test,
                                               rg=10, jrec=0,
                                               settings=settings)

        for key, val in recommendations.iteritems():
            self.assertFalse(key in records)
Ejemplo n.º 4
0
    def test_result_no_changes_when_user_is_zero_jrec_set(self):
        user_info = {'uid': '', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        settings = ObelixSearchEngineSettings(redis=self.redis)

        self.assertEqual(
            self.hitset[4:14],
            rank_records_obelix(user_info,
                                self.hitset,
                                rg=10,
                                jrec=5,
                                settings=settings)[0])
Ejemplo n.º 5
0
    def test_large_dataset_hidden_treasure_lost_without_recommendations(self):

        user_info = {'uid': '1', 'remote_ip': '127.0.0.1', 'uri': 'testuri'}

        records_to_test = range(0, 100000)
        recommendations = {90000: 1.0, 430: 0.8}

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

        settings = ObelixSearchEngineSettings(redis=self.redis)
        settings.recommendations_impact = 0

        records, scores = rank_records_obelix(user_info,
                                              records_to_test,
                                              rg=10,
                                              jrec=0,
                                              settings=settings)

        for key, val in recommendations.iteritems():
            self.assertFalse(key in records)
Ejemplo n.º 6
0
    def test_settings_read_redis(self):
        settings = {
            'redis_prefix': "obelix::",
            'recommendations_impact': 0.8,
            'score_lower_limit': 0.2,
            'score_min_limit': 10,
            'score_min_multiply': 4,
            'score_one_result': 1,
            'method_switch_limit': 30,
            'redis_timeout_search_result': 10
        }

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

        settings = ObelixSearchEngineSettings(redis=self.redis)
        self.assertEqual(settings.recommendations_impact, 0.8)
Ejemplo n.º 7
0
 def test_settings_read_default(self):
     settings = ObelixSearchEngineSettings(redis=self.redis)
     self.assertEqual(settings.recommendations_impact, 0.5)