1- package com .recombee .api_client .examples ;
2-
31import com .recombee .api_client .RecombeeClient ;
42import com .recombee .api_client .api_requests .*;
53import com .recombee .api_client .bindings .RecommendationResponse ;
64import com .recombee .api_client .bindings .Recommendation ;
5+ import com .recombee .api_client .bindings .SearchResponse ;
76import com .recombee .api_client .exceptions .ApiException ;
87
98import java .util .ArrayList ;
1312public class ItemPropertiesExample {
1413 public static void main (String [] args ) {
1514
16- RecombeeClient client = new RecombeeClient ("--my-database-id--" , "--my-secret -token--" );
15+ RecombeeClient client = new RecombeeClient ("--my-database-id--" , "--db-private -token--" );
1716
1817 try {
1918 client .send (new ResetDatabase ()); //Clear everything from the database
2019
2120 /*
2221 We will use computers as items in this example
23- Computers have three properties
22+ Computers have four properties
2423 - price (floating point number)
2524 - number of processor cores (integer number)
2625 - description (string)
26+ - image (url of computer's photo)
2727 */
2828
2929 client .send (new AddItemProperty ("price" , "double" ));
3030 client .send (new AddItemProperty ("num-cores" , "int" ));
3131 client .send (new AddItemProperty ("description" , "string" ));
32+ client .send (new AddItemProperty ("image" , "image" ));
3233
3334 // Prepare requests for setting a catalog of computers
3435 final ArrayList <Request > requests = new ArrayList <Request >();
@@ -37,13 +38,15 @@ public static void main(String[] args) {
3738
3839 for (int i =0 ; i <NUM ; i ++)
3940 {
41+ final String itemId = String .format ("computer-%s" ,i );
4042 final SetItemValues req = new SetItemValues (
41- String . format ( "computer-%s" , i ), // itemId
43+ itemId ,
4244 //values:
4345 new HashMap <String , Object >() {{
4446 put ("price" , 600.0 + 400 *rand .nextDouble ());
4547 put ("num-cores" , 1 + rand .nextInt (7 ));
4648 put ("description" , "Great computer" );
49+ put ("image" , String .format ("http://examplesite.com/products/%s.jpg" , itemId ));
4750 }}
4851 ).setCascadeCreate (true ); // Use cascadeCreate for creating item
4952 // with given itemId, if it doesn't exist;
@@ -65,14 +68,10 @@ public static void main(String[] args) {
6568
6669
6770 // Get 5 recommendations for user-42, who is currently viewing computer-6
68- RecommendationResponse recommendationResponse = client .send (new RecommendItemsToItem ("computer-6" , "user-42" , 5 ));
69- System .out .println ("Recommended items:" );
70- for (Recommendation rec : recommendationResponse ) System .out .println (rec .getId ());
71-
72-
7371 // Recommend only computers that have at least 3 cores
74- recommendationResponse = client .send (new RecommendItemsToItem ("computer-6" , "user-42" , 5 )
75- .setFilter (" 'num-cores'>=3 " ));
72+ RecommendationResponse recommendationResponse = client .send (
73+ new RecommendItemsToItem ("computer-6" , "user-42" , 5 )
74+ .setFilter (" 'num-cores'>=3 " ));
7675 System .out .println ("Recommended items with at least 3 processor cores:" );
7776 for (Recommendation rec : recommendationResponse ) System .out .println (rec .getId ());
7877
@@ -83,9 +82,23 @@ public static void main(String[] args) {
8382 System .out .println ("Recommended up-sell items:" );
8483 for (Recommendation rec : recommendationResponse ) System .out .println (rec .getId ());
8584
85+
86+ // Filters, boosters and other settings can be set also in the Admin UI (admin.recombee.com)
87+ // when scenario is specified
88+ recommendationResponse = client .send (
89+ new RecommendItemsToItem ("computer-6" , "user-42" , 5 ).setScenario ("product_detail" )
90+ );
91+
92+ // Perform personalized full-text search with a user's search query (e.g. "computers")
93+ SearchResponse searchResponse = client .send (
94+ new SearchItems ("user-42" , "computers" , 5 )
95+ );
96+ System .out .println ("Search matches:" );
97+ for (Recommendation rec : searchResponse ) System .out .println (rec .getId ());
98+
8699 } catch (ApiException e ) {
87100 e .printStackTrace ();
88101 //Use fallback
89102 }
90103 }
91- }
104+ }
0 commit comments