Beispiel #1
0
  @Override
  public List<RecommendedItem> recommend(
      long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
      throws TasteException {
    Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
    synchronized (maxHowMany) {
      if (howMany > maxHowMany[0]) {
        maxHowMany[0] = howMany;
      }
    }

    // Special case, avoid caching an anonymous user
    if (userID == PlusAnonymousUserDataModel.TEMP_USER_ID) {
      return recommendationsRetriever.get(PlusAnonymousUserDataModel.TEMP_USER_ID).getItems();
    }

    setCurrentRescorer(rescorer);
    setCurrentlyIncludeKnownItems(includeKnownItems);

    Recommendations recommendations = recommendationCache.get(userID);
    if (recommendations.getItems().size() < howMany
        && !recommendations.isNoMoreRecommendableItems()) {
      clear(userID);
      recommendations = recommendationCache.get(userID);
      if (recommendations.getItems().size() < howMany) {
        recommendations.setNoMoreRecommendableItems(true);
      }
    }

    List<RecommendedItem> recommendedItems = recommendations.getItems();
    return recommendedItems.size() > howMany
        ? recommendedItems.subList(0, howMany)
        : recommendedItems;
  }
Beispiel #2
0
 /**
  * Clears cached recommendations for the given user.
  *
  * @param userID clear cached data associated with this user ID
  */
 public void clear(final long userID) {
   log.debug("Clearing recommendations for user ID '{}'", userID);
   recommendationCache.remove(userID);
   estimatedPrefCache.removeKeysMatching(
       new Cache.MatchPredicate<LongPair>() {
         @Override
         public boolean matches(LongPair userItemPair) {
           return userItemPair.getFirst() == userID;
         }
       });
 }
 @Override
 public void refresh(Collection<Refreshable> alreadyRefreshed) {
   neighborhoodCache.clear();
   alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
   RefreshHelper.maybeRefresh(alreadyRefreshed, neighborhood);
 }
 @Override
 public long[] getUserNeighborhood(long userID) throws TasteException {
   return neighborhoodCache.get(userID);
 }
Beispiel #5
0
 /** Clears all cached recommendations. */
 public void clear() {
   log.debug("Clearing all recommendations...");
   recommendationCache.clear();
   estimatedPrefCache.clear();
 }
Beispiel #6
0
 @Override
 public float estimatePreference(long userID, long itemID) throws TasteException {
   return estimatedPrefCache.get(new LongPair(userID, itemID));
 }