Module Contents



Simulates the orderby=random from SQL.

class core.bones.randomSliceBone.randomSliceBone(visible=False, readOnly=True, slices=2, sliceSize=0.5, *args, **kwargs)

Bases: viur.core.bones.baseBone

Simulates the orderby=random from SQL. If you sort by this bone, the query will return a random set of elements from that query.

type = randomslice
serialize(self, skel: SkeletonInstance, name: str, parentIndexed: bool) bool

Serializes this bone into something we can write into the datastore.

This time, we just ignore whatever is set on this bone and write a randomly chosen float [0..1) as value for this bone.


name (str) – The property-name this bone has in its Skeleton (not the description!)



buildDBSort(self, name, skel, dbFilter, rawFilter)

Same as buildDBFilter, but this time its not about filtering the results, but by sorting them. Again: rawFilter is controlled by the client, so you must expect and safely handle malformed data!

This function is somewhat special as it doesn’t just change in which order the selected Elements are being returned - but also changes which Elements are beeing returned (=> a random selection)

  • name (str) – The property-name this bone has in its Skeleton (not the description!)

  • skel (server.skeleton.Skeleton) – The server.skeleton.Skeleton instance this bone is part of

  • dbFilter (server.db.Query) – The current server.db.Query instance the filters should be applied to

  • rawFilter (dict) – The dictionary of filters the client wants to have applied


The modified server.db.Query

calculateInternalMultiQueryLimit(self, targetAmount)

Tells server.db.Query How much entries should be fetched in each subquery.


targetAmount (int) – How many entries shall be returned from db.Query


The amount of elements db.Query should fetch on each subquery

Return type


customMultiQueryMerge(self, dbFilter, result, targetAmount)

Randomly returns ‘targetAmount’ elements from ‘result’

  • dbFilter – The db.Query calling this function

  • result (list of list of server.db.Entity) – The list of results for each subquery we’ve run

  • targetAmount (int) – How many results should be returned from db.Query


dbFilter: server.db.Query


list of elements which should be returned from db.Query

Return type

list of server.db.Entity