1
- package com .recombee .api_client .examples ;
2
-
3
1
import com .recombee .api_client .RecombeeClient ;
4
2
import com .recombee .api_client .api_requests .*;
5
3
import com .recombee .api_client .bindings .RecommendationResponse ;
6
4
import com .recombee .api_client .bindings .Recommendation ;
5
+ import com .recombee .api_client .bindings .SearchResponse ;
7
6
import com .recombee .api_client .exceptions .ApiException ;
8
7
9
8
import java .util .ArrayList ;
13
12
public class ItemPropertiesExample {
14
13
public static void main (String [] args ) {
15
14
16
- RecombeeClient client = new RecombeeClient ("--my-database-id--" , "--my-secret -token--" );
15
+ RecombeeClient client = new RecombeeClient ("--my-database-id--" , "--db-private -token--" );
17
16
18
17
try {
19
18
client .send (new ResetDatabase ()); //Clear everything from the database
20
19
21
20
/*
22
21
We will use computers as items in this example
23
- Computers have three properties
22
+ Computers have four properties
24
23
- price (floating point number)
25
24
- number of processor cores (integer number)
26
25
- description (string)
26
+ - image (url of computer's photo)
27
27
*/
28
28
29
29
client .send (new AddItemProperty ("price" , "double" ));
30
30
client .send (new AddItemProperty ("num-cores" , "int" ));
31
31
client .send (new AddItemProperty ("description" , "string" ));
32
+ client .send (new AddItemProperty ("image" , "image" ));
32
33
33
34
// Prepare requests for setting a catalog of computers
34
35
final ArrayList <Request > requests = new ArrayList <Request >();
@@ -37,13 +38,15 @@ public static void main(String[] args) {
37
38
38
39
for (int i =0 ; i <NUM ; i ++)
39
40
{
41
+ final String itemId = String .format ("computer-%s" ,i );
40
42
final SetItemValues req = new SetItemValues (
41
- String . format ( "computer-%s" , i ), // itemId
43
+ itemId ,
42
44
//values:
43
45
new HashMap <String , Object >() {{
44
46
put ("price" , 600.0 + 400 *rand .nextDouble ());
45
47
put ("num-cores" , 1 + rand .nextInt (7 ));
46
48
put ("description" , "Great computer" );
49
+ put ("image" , String .format ("http://examplesite.com/products/%s.jpg" , itemId ));
47
50
}}
48
51
).setCascadeCreate (true ); // Use cascadeCreate for creating item
49
52
// with given itemId, if it doesn't exist;
@@ -65,14 +68,10 @@ public static void main(String[] args) {
65
68
66
69
67
70
// 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
-
73
71
// 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 " ));
76
75
System .out .println ("Recommended items with at least 3 processor cores:" );
77
76
for (Recommendation rec : recommendationResponse ) System .out .println (rec .getId ());
78
77
@@ -83,9 +82,23 @@ public static void main(String[] args) {
83
82
System .out .println ("Recommended up-sell items:" );
84
83
for (Recommendation rec : recommendationResponse ) System .out .println (rec .getId ());
85
84
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
+
86
99
} catch (ApiException e ) {
87
100
e .printStackTrace ();
88
101
//Use fallback
89
102
}
90
103
}
91
- }
104
+ }
0 commit comments