Collection

Overview

The collection is the heart of ItemsAPI. It generates the logic for filters, searching and sorting so then everything can work out of the box.

Simple example

[
  {
    "name": "movie",
    "project": "itemsapi",
    "schema": {
      "name": {"type": "string", "store": true },
      "image": {"type": "string", "display": "image" },
      "year": {"type": "integer", "store": true },
      "votes": {"type": "integer", "store": true },
      "director": {"type": "string", "index": "not_analyzed", "store": true },
      "actors": {"type": "string", "index": "not_analyzed", "display": "array", "store": true },
      "tags": {"type": "string", "display": "array", "store": true },
      "rating": {"type": "float", "store": true }
    }
  }
]

Full example

Below is version with aggregations and sortings:

[
  {
    "name": "movie",
    "project": "itemsapi",
    "meta": {
      "title": "Movies",
      "created": "spring 2015"
    },
    "schema": {
      "name": {"type": "string", "store": true },
      "image": {"type": "string", "display": "image" },
      "year": {"type": "integer", "store": true },
      "votes": {"type": "integer", "store": true },
      "director": {"type": "string", "index": "not_analyzed", "store": true },
      "actors": {"type": "string", "index": "not_analyzed", "display": "array", "store": true },
      "tags": {"type": "string", "display": "array", "store": true },
      "rating": {"type": "float", "store": true }
    },
    "sortings": {
      "rating": {
        "title": "Best rating",
        "type": "normal",
        "order": "desc",
        "field": "rating"
      },
      "most_votes": {
        "title": "Most votes",
        "type": "normal",
        "order": "desc",
        "field": "votes"
      },
      "year_newest": {
        "title": "Newest movies",
        "type": "normal",
        "order": "desc",
        "field": "year"
      },
      "year_oldest": {
        "title": "Oldest movies",
        "type": "normal",
        "order": "asc",
        "field": "year"
      }
    },
    "slugs": ["actors"],
    "aggregations": {
      "actors_terms": {"type": "terms", "field": "actors", "size": 10, "title": "Actors"},
      "director_terms": {"type": "terms", "field": "director", "size": 5, "title": "Directors"},
      "tags_terms": {"type": "terms", "field": "tags", "size": 10, "title": "Tags"},

      "votes_range": {
        "type": "range",
        "field": "votes",
        "title": "Votes range",
        "ranges": [
          {"lte": 300, "name": " 3000"}
        ]
      },
      "years_range": {
        "type": "range",
        "field": "year",
        "title": "Years range",
        "ranges": [
          {"lte": 1950, "name": "1950 - 1960"},
          {"gte": 1950, "lte": 1960, "name": "1950 - 1960"},
          {"gte": 1960, "lte": 1970, "name": "1960 - 1970"},
          {"gte": 1970, "lte": 1980, "name": "1970 - 1980"},
          {"gte": 1980, "lte": 1990, "name": "1980 - 1990"},
          {"gte": 1990, "lte": 2000, "name": "1990 - 2000"},
          {"gte": 2000, "lte": 2010, "name": "2000 - 2010"},
          {"gte": 2010, "name": "> 2010"}
        ]
      },
      "rating_range": {
        "type": "range",
        "field": "rating",
        "title": "Rating range",
        "ranges": [
          {"lte": 1, "name": "0 - 1"},
          {"gte": 1, "lte": 2, "name": "1 - 2"},
          {"gte": 2, "lte": 3, "name": "2 - 3"},
          {"gte": 3, "lte": 4, "name": "3 - 4"},
          {"gte": 4, "lte": 5, "name": "4 - 5"},
          {"gte": 5, "lte": 6, "name": "5 - 6"},
          {"gte": 6, "lte": 7, "name": "6 - 7"},
          {"gte": 7, "lte": 8, "name": "7 - 8"},
          {"gte": 8, "lte": 9, "name": "8 - 9"},
          {"gte": 9, "name": "9 - 10"}
        ]
      }
    }
  }
]

It is quite long but very powerful and it is responsible for the API generation and whole logic.

Was this page helpful ?