yes, the shopping cart query options are not all documented on the site yet but you can read them here:
https://github.com/actionml/universal-recommender/blob/master/src/main/scala/Engine.scala#L32 <https://github.com/actionml/universal-recommender/blob/master/src/main/scala/Engine.scala#L32> Which led me to notice that the query should be: curl -H "Content-Type: application/json" -d '{"itemSet" : ["1"]}'http://localhost:8000/queries.json <http://localhost:8000/queries.json> “itemSet” not "item-set" On May 23, 2017, at 2:37 PM, Dennis Honders <[email protected]> wrote: Thanks for the answer. I remember the user part. Every cart is treated as a new one so user-based won't be used in this case. Is 'item-set' a specific keyword for the item-based query? (curl -H "Content-Type: application/json" -d '{"item-set" : ["1"]}'http://localhost:8000/queries.json <http://localhost:8000/queries.json>) If so, I think I might know why I got the gson error. Op 23 mei 2017 om 20:47 heeft Pat Ferrel <[email protected] <mailto:[email protected]>> het volgende geschreven: > I assume you are using 0.6.0 so you’ll have to wait for docs in progress. > > Remember that you are substituting the cart id for the typical user id so do > a user-based query with the cart id but passed in as “user", or send a list > of items as “item-set” in the query. > > curl -H "Content-Type: application/json" -d '{"user" : "1"}' > http://localhost:8000/queries.json <http://localhost:8000/queries.json> # > notice query is a cart id > curl -H "Content-Type: application/json" -d '{"item-set" : ["1"]}' > http://localhost:8000/queries.json <http://localhost:8000/queries.json> # > notice the query is a set of item-ids > > for this to work there must be a “user” of id “1” with the cart contents > recorded from "cart-transaction” events. The item-set query should work > regardless of cart ids since you are passing in a list of item-ids in the > cart. > > > On May 23, 2017, at 10:07 AM, Dennis Honders <[email protected] > <mailto:[email protected]>> wrote: > > Still same questions as previous. > > Addition to this mail: > > Engine.json > { > "comment":" This config file uses default settings for all but the required > values see README.md for docs", > "id": "default", > "description": "Default settings", > "engineFactory": "com.actionml.RecommendationEngine", > "datasource": { > "params" : { > "name": "ur-name", > "appName": "Test", > "eventNames": ["cart-transaction"] > } > }, > "sparkConf": { > "spark.serializer": "org.apache.spark.serializer.KryoSerializer", > "spark.kryo.registrator": > "org.apache.mahout.sparkbindings.io.MahoutKryoRegistrator", > "spark.kryo.referenceTracking": "false", > "spark.kryoserializer.buffer.mb": "300", > "spark.kryoserializer.buffer": "300m", > "es.index.auto.create": "true" > }, > "algorithms": [ > { > "comment": "simplest setup where all values are default, popularity > based backfill, must add eventsNames", > "name": "ur", > "params": { > "appName": "Test", > "indexName": "test", > "typeName": "cart", > "comment": "must have data for the first event or the model will not > build, other events are optional", > "eventNames": ["cart-transaction"] > }, > "blacklistEvents": [], > "num": 10, > "maxQueryEvents": 20 > } > ] > } > > Also tried the following (added quotes to the json): > > curl -H "Content-Type: application/json" -d '{"cart" : ["1"]}' > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > curl -H "Content-Type: application/json" -d '{"item" : ["1"]}' > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > curl -H "Content-Type: application/json" -d '{"items" : ["1"]}' > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > > Retrieved the following error: > > Stack Trace: > com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: > Expected BEGIN_OBJECT but was STRING at line 1 column 2 > at > com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176) > at com.google.gson.Gson.fromJson(Gson.java:803) > at com.google.gson.Gson.fromJson(Gson.java:768) > at com.google.gson.Gson.fromJson(Gson.java:717) > at com.google.gson.Gson.fromJson(Gson.java:689) > at > org.apache.predictionio.workflow.JsonExtractor$.extractWithGson(JsonExtractor.scala:155) > at > org.apache.predictionio.workflow.JsonExtractor$.extract(JsonExtractor.scala:73) > at > org.apache.predictionio.workflow.ServerActor$$anonfun$24.apply(CreateServer.scala:479) > at > org.apache.predictionio.workflow.ServerActor$$anonfun$24.apply(CreateServer.scala:473) > at > spray.routing.ApplyConverterInstances$$anon$22$$anonfun$apply$1.apply(ApplyConverterInstances.scala:25) > at > spray.routing.ApplyConverterInstances$$anon$22$$anonfun$apply$1.apply(ApplyConverterInstances.scala:24) > at > spray.routing.ConjunctionMagnet$$anon$1$$anon$2$$anonfun$happly$1$$anonfun$apply$1.apply(Directive.scala:38) > at > spray.routing.ConjunctionMagnet$$anon$1$$anon$2$$anonfun$happly$1$$anonfun$apply$1.apply(Directive.scala:37) > at > spray.routing.directives.BasicDirectives$$anon$1.happly(BasicDirectives.scala:26) > at > spray.routing.ConjunctionMagnet$$anon$1$$anon$2$$anonfun$happly$1.apply(Directive.scala:37) > at > spray.routing.ConjunctionMagnet$$anon$1$$anon$2$$anonfun$happly$1.apply(Directive.scala:36) > at > spray.routing.directives.BasicDirectives$$anon$2.happly(BasicDirectives.scala:79) > at > spray.routing.Directive$$anon$7$$anonfun$happly$4.apply(Directive.scala:86) > at > spray.routing.Directive$$anon$7$$anonfun$happly$4.apply(Directive.scala:86) > at > spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92) > at > spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92) > at > spray.routing.directives.ExecutionDirectives$$anonfun$detach$1$$anonfun$apply$7$$anonfun$apply$3.apply$mcV$sp(ExecutionDirectives.scala:89) > at > spray.routing.directives.ExecutionDirectives$$anonfun$detach$1$$anonfun$apply$7$$anonfun$apply$3.apply(ExecutionDirectives.scala:89) > at > spray.routing.directives.ExecutionDirectives$$anonfun$detach$1$$anonfun$apply$7$$anonfun$apply$3.apply(ExecutionDirectives.scala:89) > at > scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) > at > scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) > at > scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107) > at > scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) > at > scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) > at > scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) > at > scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) > Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was > STRING at line 1 column 2 > at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374) > at > com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165) > ... 30 more > > Still same questions as previous mail. > > 2017-05-23 16:23 GMT+02:00 Dennis Honders <[email protected] > <mailto:[email protected]>>: > I trained and deployed the universal recommender. > I only get the populair products as a result. > > Trainingdata > > [ > {"event": "cart-transaction", "entityId": "1", "entityType": "user", > "targetEntityId": "12", "targetEntityType": "item"}, > {"event": "cart-transaction", "entityId": "1", "entityType": "user", > "targetEntityId": "13", "targetEntityType": "item"}, > {"event": "cart-transaction", "entityId": "1", "entityType": "user", > "targetEntityId": "14", "targetEntityType": "item"} > ] > > {"event": "$set", "entityType": "item", "entityId": "12", "properties": > {"category": ["1", "2", "3", "4", "5", "6", "7"], "manufacturer": 1, "label": > "test", "price": "$1-$2"}} > > Query > curl -H "Content-Type: application/json" -d { "item": ["1"]} > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > > curl -H "Content-Type: application/json" -d { "items": ["1"]} > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > > curl -H "Content-Type: application/json" -d { "cart-transaction": ["1"]} > http://localhost:8000/queries.json <http://localhost:8000/queries.json> > > Result > The populair (most bought) items, also for products that are sold a lot. > > Log: > > [INFO] [URAlgorithm] No user id for recs, returning item-based recs if an > item is specified in the query. > [INFO] [URAlgorithm] Query: > {"size":10,"query":{"bool":{"should":[{"terms":{"cart-transaction":[]}},{"constant_score":{"filter":{"match_all":{}},"boost":0}}],"must":[],"must_not":[{"ids":{"values":[],"boost":0}}],"minimum_should_match":1}},"sort":[{"_score":{"order":"desc"}},{"popRank":{"unmapped_type":"double","order":"desc"}}]} > [INFO] [URAlgorithm] Results: 10 retrieved of a possible 70658 > > Is the query correct? > > What else could be the problem here? > > Note: I also like to return 'similar items' (based on properties) when no > relation could be found with 'buy'. > >
