Change to use LEvents findSingleEntity
diff --git a/README.md b/README.md
index 3595257..f1081ce 100644
--- a/README.md
+++ b/README.md
@@ -28,9 +28,6 @@
   "num" : 10 }' \
 http://localhost:8000/queries.json \
 -w %{time_connect}:%{time_starttransfer}:%{time_total}
-
-
-{"itemScores":[{"item":"i43","score":0.9987465791873191},{"item":"i21","score":0.9987465791873191},{"item":"i20","score":0.997849496769407},{"item":"i49","score":0.9969960024975738},{"item":"i41","score":0.9955226345451645},{"item":"i37","score":0.9953403563456491},{"item":"i8","score":0.9944547925923641},{"item":"i46","score":0.9928301245473273},{"item":"i1","score":0.9910679754780729},{"item":"i18","score":0.9903295848514115}]}
 ```
 
 ```
@@ -93,7 +90,7 @@
 import some view events and try to get recommendation for x1 again.
 
 ```
-curl -i -X POST http://localhost:7070/events.json?accessKey=s49uNadpNh5C4cRGCCIp8NqK1UWkaQPsN1SN2y670pZfRVXsbUepzmZQmyfjWeHo \
+curl -i -X POST http://localhost:7070/events.json?accessKey=zPkr6sBwQoBwBjVHK2hsF9u26L38ARSe19QzkdYentuomCtYSuH0vXP5fq7advo4 \
 -H "Content-Type: application/json" \
 -d '{
   "event" : "view",
@@ -104,7 +101,7 @@
   "eventTime" : "2015-02-17T02:11:21.934Z"
 }'
 
-curl -i -X POST http://localhost:7070/events.json?accessKey=s49uNadpNh5C4cRGCCIp8NqK1UWkaQPsN1SN2y670pZfRVXsbUepzmZQmyfjWeHo \
+curl -i -X POST http://localhost:7070/events.json?accessKey=zPkr6sBwQoBwBjVHK2hsF9u26L38ARSe19QzkdYentuomCtYSuH0vXP5fq7advo4 \
 -H "Content-Type: application/json" \
 -d '{
   "event" : "view",
@@ -122,7 +119,7 @@
 Set the following items "unavailable" (need to specify complete list each time when this list is changed):
 
 ```
-curl -i -X POST http://localhost:7070/events.json?accessKey=s49uNadpNh5C4cRGCCIp8NqK1UWkaQPsN1SN2y670pZfRVXsbUepzmZQmyfjWeHo \
+curl -i -X POST http://localhost:7070/events.json?accessKey=zPkr6sBwQoBwBjVHK2hsF9u26L38ARSe19QzkdYentuomCtYSuH0vXP5fq7advo4 \
 -H "Content-Type: application/json" \
 -d '{
   "event" : "$set",
@@ -138,7 +135,7 @@
 No more items "unavailable":
 
 ```
-curl -i -X POST http://localhost:7070/events.json?accessKey=s49uNadpNh5C4cRGCCIp8NqK1UWkaQPsN1SN2y670pZfRVXsbUepzmZQmyfjWeHo \
+curl -i -X POST http://localhost:7070/events.json?accessKey=zPkr6sBwQoBwBjVHK2hsF9u26L38ARSe19QzkdYentuomCtYSuH0vXP5fq7advo4 \
 -H "Content-Type: application/json" \
 -d '{
   "event" : "$set",
diff --git a/engine.json b/engine.json
index a8f5576..7c794ba 100644
--- a/engine.json
+++ b/engine.json
@@ -11,7 +11,7 @@
     {
       "name": "als",
       "params": {
-        "appId": 16,
+        "appId": 17,
         "unseenOnly": true,
         "seenEvents": ["view"],
         "rank": 10,
diff --git a/src/main/scala/ALSAlgorithm.scala b/src/main/scala/ALSAlgorithm.scala
index cd424fe..73ffa87 100644
--- a/src/main/scala/ALSAlgorithm.scala
+++ b/src/main/scala/ALSAlgorithm.scala
@@ -154,12 +154,13 @@
     // if unseenOnly is True, get all seen items
     val seenItems: Set[String] = if (ap.unseenOnly) {
 
-      val seenEvents: Iterator[Event] = lEventsDb.find(
+      // get all user item events which are considered as "seen" events
+      val seenEvents: Iterator[Event] = lEventsDb.findSingleEntity(
         appId = ap.appId,
-        // entityType and entityId is specified for fast lookup
-        entityType = Some("user"),
-        entityId = Some(query.user),
+        entityType = "user",
+        entityId = query.user,
         eventNames = Some(ap.seenEvents),
+        targetEntityType = Some(Some("item")),
         // set time limit to avoid super long DB access
         timeout = Duration(200, "millis")
       ) match {
@@ -184,14 +185,14 @@
       Set[String]()
     }
 
-    val unavailableItems: Set[String] = lEventsDb.find(
+    // get the latest itemConstraint unavailable $set event
+    val unavailableItems: Set[String] = lEventsDb.findSingleEntity(
       appId = ap.appId,
-      // entityType and entityId is specified for fast lookup
-      entityType = Some("itemConstraint"),
-      entityId = Some("unavailable"),
+      entityType = "itemConstraint",
+      entityId = "unavailable",
       eventNames = Some(Seq("$set")),
       limit = Some(1),
-      reversed = Some(true),
+      latest = true,
       timeout = Duration(200, "millis")
     ) match {
       case Right(x) => {
@@ -283,15 +284,16 @@
     val userFeatures = model.userFeatures
     val productFeatures = model.productFeatures
 
-    // get recent view events
-    val recentEvents = lEventsDb.find(
+    // get latest 10 user view item events
+    val recentEvents = lEventsDb.findSingleEntity(
       appId = ap.appId,
       // entityType and entityId is specified for fast lookup
-      entityType = Some("user"),
-      entityId = Some(query.user),
+      entityType = "user",
+      entityId = query.user,
       eventNames = Some(Seq("view")),
+      targetEntityType = Some(Some("item")),
       limit = Some(10),
-      reversed = Some(true),
+      latest = true,
       // set time limit to avoid super long DB access
       timeout = Duration(200, "millis")
     ) match {