In general this DataModel is not modifiable, which is why you're
having to hack at it. The idea is to update the underlying data,
ideally -- for example, the file containing the data, perhaps by using
update (delta) files.

Your approach works though. There is not a better way to do it, if
this is what you're doing.

As Ted mentioned, keep data on items that are real and valid, just out
of stock or old or something. You can filter them using a Rescorer so
that they don't end up in the output.

You can do the same thing for ghost data, if you like. That at least
means you have an immediate way of filtering and can wait for a data
reload or update rather than do it every time on the fly.

On Mon, Oct 17, 2011 at 2:58 AM, Octavian Covalschi
<[email protected]> wrote:
> 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