storages Package¶
base
Module¶
-
class
recommends.storages.base.
BaseRecommendationStorage
(settings=None)[source]¶ Bases:
object
-
can_lock
= False¶
-
get_identifier
(obj, site_id=None, rating=None, *args, **kwargs)[source]¶ Given an object and optional parameters, returns a string identifying the object uniquely.
-
get_recommendations_for_user
(user, limit, raw_id=False)[source]¶ - if raw_id = False:
- Returns a list of
Recommendation
objects for givenuser
, ordered by score. - else:
Returns a list of recommended
model
ids[pk] for givenuser
, ordered by score.Example:
- ::
- [
- {
- “object_id”: XX, “contect_type_id”: XX
]
-
get_similarities_for_object
(obj, limit, raw_id=False)[source]¶ - if raw_id = False:
- Returns a list of
Similarity
objects for givenobj
, ordered by score. - else:
Returns a list of similar
model
ids[pk] for givenobj
, ordered by score.Example:
[ { "related_object_id": XX, "contect_type_id": XX }, .. ]
-
get_votes
()[source]¶ Optional.
Retrieves the vote matrix saved by
store_votes
.You won’t usually need to implement this method, because you want to use fresh data. But it might be useful if you want some kind of heavy caching, maybe for testing purposes.
-
resolve_identifier
(identifier)[source]¶ This method is the opposite of
get_identifier
. It resolve the object’s identifier to an actual model.
-
store_recommendations
(recommendations)[source]¶ Stores all the recommendations.
recommendations
is an iterable with the following schema:( ( <user>, ( (<object_identifier>, <score>), (<object_identifier>, <score>) ), ) )
-
store_votes
(iterable)[source]¶ Optional.
Saves the vote matrix.
You won’t usually need to implement this method, because you want to use fresh data. But it might be useful if you want to dump the votes on somewhere, maybe for testing purposes.
iterable
is the vote matrix, expressed as a list of tuples with the following schema:[ ("<user_id1>", "<object_identifier1>", <score>), ("<user_id1>", "<object_identifier2>", <score>), ("<user_id2>", "<object_identifier1>", <score>), ("<user_id2>", "<object_identifier2>", <score>), ]
-
threshold_recommendations
= 0¶
-
threshold_similarities
= 0¶
-