Factories
Factories expose an additional level of control over the internal Squirro objects. They can be used to mock, and create arbitrary data collections.
Collections
Items
Creates a Squirro Items collection.
Factories.Collections.Items.create(search, project)
Example
getCollection: function () { return Factories.Collections.Items.create(this.options.search, this.options.project) },
Facets
Creates a Squirro Facets collection.
Factories.Collections.Facets.create(search, project, options)
Example
getCollection: function () { return Factories.Collections.Facets.create(this.options.search, this.options.project, { facet_fields: [ 'custom_facet' ], // custom facets to fetch nof_facets: 100, // maximum number of facet values returned itemsCollection: Factories.Collections.Items.create(this.options.search, this.options.project), // associate (optionally) a custom Items collection }); },
Once the collection has been fetched, the aggregation results are accessed as collection.indexed.custom_facet
with custom_facet
being the name of the requested aggregation in the request.
MockItems
Creates a Squirro Items collection. It is possible to throw a JSON object with mocked items at it, to be used as an alternative data source to Squirro backend.
Factories.Collections.MockItems.create(search, project, items)
Example
return Widgets.Search.extend({ _feedItems: function () { return [{ 'created_at': '2016-10-17T11:02:11', 'title': 'Custom Title', 'abstract': 'Custom Abstract', }]; }, getCollection: function () { return Factories.Collections.MockItems.create(this.options.search, this.options.project, this._feedItems()); }, });