Custom Axes
Group activities by shared fields and choose which custom group takes priority.
Defining Custom Axes
Define a custom axis with the fields activities must share and the threshold they must meet:
use Storyfeed\Facades\Storyfeed;
use Storyfeed\Grouping\Axis;
$scene = Axis::make('scene')
->key('v:ca!:cid!:d')
->eligibleWhenDistinct('actor', min: 2);
Storyfeed::axes([$scene]);Activities published from now on are grouped on the new axis. To apply it to stored activities, rehash them:
php artisan storyfeed:curate --rehashHere, scene groups activities in the same context, such as three customers asking about dishes in one shop. Use $group->axis('scene', …) inside grouped() to define its headline, or $group->any(…) to match any axis.
use Storyfeed\Facades\Story;
use Storyfeed\Grouping\GroupBuilder;
Story::verb('ask')->grouped(fn (GroupBuilder $group): GroupBuilder => $group
->axis('scene', ':actors asked questions in :context')
->actorsOnTarget(':actors asked about :target'));Two customers sharing a context meet this axis's threshold but not the built-in actors_target threshold, so the query returns a scene group:
Axis Keys
Separate shared fields with :. Add ! after a field to exclude activities where it is empty.
| Role | Type Field | Id Field |
|---|---|---|
actor | aa | aid |
object | oa | oid |
target | ta | tid |
context | ca | cid |
origin | ora | orid |
result | ra | rid |
instrument | ia | iid |
location | la | lid |
generator | ga | gid |
See Default Grouping Keys for the built-in axes.
Built-in axes assign their keys to persisted bursts. Custom axes may add v to group by verb and d to group by calendar period (a day by default). A singular token such as :context requires both of that role's fields in the key. Without v, the group may contain several verbs, so define its headline on Story::fallback(), which applies to every verb:
use Storyfeed\Facades\Story;
use Storyfeed\Grouping\GroupBuilder;
Story::fallback()->grouped(fn (GroupBuilder $group): GroupBuilder => $group
->axis('visits', ':actors were busy in :context'));Here, visits is an axis registered with the key ca!:cid!:d.
Calendar Periods
Calendar declarations such as groupedWeekly() apply to custom axes whose keys include the calendar field d. Built-in Live axes use burst windows.
use Storyfeed\Facades\Story;
Story::verb('ask')->groupedWeekly();The scene key above includes d, so this declaration groups each week's questions separately. Calendar boundaries use the application's timezone.
Prioritizing Axes
With three customers, both actors_target and scene qualify. The built-in actors_target axis has priority and selects the group:
New axes have the lowest priority among selectable axes. To put scene before actors_target, reuse the $scene defined above:
use Storyfeed\Facades\Storyfeed;
Storyfeed::axes([$scene], before: 'actors_target');After group selection runs with this priority, the same activities form a scene group that names their shared context: