Last modified: 2011-09-09 13:40:26 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T32835, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 30835 - Support for selecting a random result in a query
Support for selecting a random result in a query
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
unspecified
All All
: Unprioritized normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-09 12:53 UTC by Jamie Thingelstad
Modified: 2011-09-09 13:40 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Jamie Thingelstad 2011-09-09 12:53:41 UTC
There are times when it would be useful to be able to get a random item from a SMW query. For example, if you have a query that retrieves a random quote from a set of quotes.

One way to do this would be to add a sort method called "random" or "shuffle" that would just scramble the result set before sending. This could be paired with a limit of 1 to get a single random result, or a handful.

This is particularly needed when using a JSON query where there is too much data to return the entire result set to the client to then pick a random item.
Comment 1 Jeroen De Dauw 2011-09-09 13:40:26 UTC
This functionality already exists. 

* The sort parameter takes some property to sort on
* The order parameter indicates how the sort should happen, and accepts "random"

So a query with

{{#ask::
...
| sort=Some property
| order=random
| limit=1
}}

should work.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links