Activity Engine
A tutorial showing how to use the Sensei Activity Engine
Description
Sensei activity datastore is used to keep volatile field values outside of the Lucene's index. This allows partial updates and supports high indexing update rate for the Sensei
Configuration
Currently only int fields are supported as activity fields. To specify the activity column, use the following configuration
<table ... <column name="likes" activity="true" type="int"/> </table> <facets> ... <facet name="likes" type="range"/> </facets>
Now you can issue the range queries for the "likes" facet
{"selections": [{"range": {"likes": {"from": 18, "include_lower": true}}}], "sort":[{"likes":"desc"}]}
Please be advised that activity range query performance might be slower comparing to usual Sensei range queries. It's better to use activity fields for sorting and relevance
Time aggregates support
If we want to store the activity data and keep track of all the updates for particular time, we can use the following configuration:
<table ... <column name="likes" activity="true" type="int"/> </table> <facets> ... <facet name="likes" column="likes" type="aggregated-range"> <params> <param name="time" value="5m" /> <param name="time" value="15m" /> <param name="time" value="1h" /> <param name="time" value="12h" /> <param name="time" value="1d" /> <param name="time" value="7d" /> <param name="time" value="2w" /> </params> </facet> </facets>
Now you can issue the range queries for the time aggregates
{"selections": [{"range": {"likes:15m": {"from": 18, "include_lower": true}}}], "sort":[{"likes:15m":"desc"}]}
And we still can access the non-aggregated values
{"selections": [{"range": {"likes": {"from": 18, "include_lower": true}}}], "sort":[{"likes":"desc"}]}
Indexing
To index the activity value, add the activity field and value to the Json document
{"id":5, "color":"blue", "likes" : 25}
This would set the "likes" value to 25
If we just want to increment the existing value, we can do the following:
{"id":5, "type":"update", "likes" : "+4"}
Partial updates indexing
Currently Lucene doesn't support updates, the update is delete + create
So if we just want to modify the activity values for the indexed document, we may send the json document with the uid, "update" identifier and the activity field. If no other fields are present, the Lucene's index wouldn't be rebuilt. The only thing, that would be changed is the activity value
{"id":5, "type":"update", "likes" : "+1"}