Hi there.

We have the taste war running and we are trying to accomplish a realtime
functionality by removing/adding user items on the fly. So far adding and
removing items for particular users has been working fine for us and
recommendations are being changed on the fly.. though it's still in beta...
The last piece is to remove an item from ALL users, it's necessary when the
item is removed from the system... So far I've got this:

public void removeItemFromAllUsers(long itemId) throws NoSuchItemException {
        PreferenceArray prefArray = ((GenericDataModel)
delegate).getPreferencesForItem(itemId);

        if (prefArray.length() > 0) {
            FastByIDMap<PreferenceArray> rawData = ((GenericDataModel)
delegate).getRawUserData();

            for (Preference pr : prefArray) {
                PreferenceArray prefs = rawData.get(pr.getUserID());

                rawData.remove(pr.getUserID());

                if (prefs.length() > 1) {
                    PreferenceArray newPrefs = new
GenericUserPreferenceArray(length - 1);
                    for (int i = 0, j = 0; i < length; i++, j++) {
                        if (prefs.getItemID(i) == itemId) {
                            j--;
                        } else {
                            newPrefs.set(j, prefs.get(i));
                        }
                    }
                    rawData.put(pr.getUserID(), newPrefs);
                }
            }
            delegate = new GenericDataModel(rawData);
        }
    }

I'm still pretty new with mahout and was wondering if there is a better way,
in particular make use of getRawUserData(), which I tried but it didn't
help...

Thank you in advance.

Reply via email to