Databases Reference
In-Depth Information
for ( String other : productsNavigated ) {
String [] ot = other . split ( ":" );
String prod2 = ot [ 0 ];
String cat2 = ot [ 1 ];
collector . emit ( new Values ( prod1 , cat2 ));
collector . emit ( new Values ( prod2 , cat1 ));
}
addProductToHistory ( user , prodKey );
}
}
}
Note that the desired output of this bolt is to emit the products whose categories rela-
tions should be incremented.
Take a look at the source code. The bolt keeps a set of the products navigated by each
user. Note that the set contains product:category pairs rather than just products. That's
because you'll need the category information in future calls and it will perform better
if you don't need to get them from the database each time. This is possible because the
products have only one category, and it won't change during the product's lifetime.
After reading the set of the user's previously navigated products (with their categories),
check if the current product has been visited previously. If so, the entry is ignored. If
this is the first time the user has visited this product, iterate through the user's history
and emit a tuple for the product being navigated and the categories of all the products
in the history with collector.emit(new Values(prod1, cat2)) , and a second tuple for
the other products and the category of the product being navigated with collec
tor.emit(new Values(prod2, cat1)) . Finally, add the product and its category to the set.
For example, assume that the user John has the following navigation history:
User # Category
John 0 Players
John 2 Players
John 17 TVs
John 21 Mounts
And the following navigation entry needs to be processed:
User # Category
John 8 Phones
The user hasn't yet looked at product 8, so you need to process it.
 
Search WWH ::




Custom Search