Search Queries

List Queries

List queries in TakeShape provide powerful filtering and sorting features: 

query 

query ($terms: String $sort: TSSearchSort){
  getPostList(terms: $terms sort: [$sort]) {
    items {
      _id
      title
      bodyHtml
    }
    total
  }
}

variables 

{
  "terms": "Lewis",
  "sort": {
    "field": "_updatedAt",
    "order": "desc"
  }
}

In this query we search for posts with that match "Lewis"  in any of their text fields sorted by updated date in descending order. For more advanced filtering we can use the filter parameter which supports an  Elasticsearch-style JSON query.

query 

query ($filter: JSON){
  getPostList(filter: $filter) {
  	items {
      _id
      title
      bodyHtml
    }
    total
  }
}

variables 

{
  "filter": {
    "match": {
      "title": "magical"
    }
  }
}

In this example we use a match query to search the title field for the term "magical". For an exact match use a term query:

{
  "filter": {
    "term": {
      "title": "Inside the magical wardrobe"
    }
  }
}

Filtering by range:

{
  "filter": {
    "range": {
      "_updatedAt": {
        "gte": "now-3d/d",
        "lte": "now/h"
      }
    }
  }
}

This filter gets content with an _updatedAt greater than or equal to 3 days ago and less than or equal to the current hour.

Pagination

Pagination for all queries in TakeShape use the from and size arguments and total return value. 

  • from -  The offset to start from.
  • size - The maximum number of items to return. size is limited to 100.
  • total - The total number of items matching your search criteria.

Taxonomy Suggestions

In order to use the taxonomySuggest query you need to set up at least one content type as a taxonomy and add relationships from your other types to it. For example in the Shape Books sample project we have a book content type which is organized with a genre taxonomy.

query {
  taxonomySuggest(terms: "fan" contentTypeNames: ["book"]) {
    items {
      _id
      _contentTypeName
      text
    }
  }
}

This query looks for taxonomy items related to book which match "fan".

{
  "data": {
    "taxonomySuggest": {
      "items": [
        {
          "_id": "02a52a5a-aea1-4aed-9a46-799c14354a71",
          "_contentTypeName": "genre",
          "text": "Fantasy"
        }
      ]
    }
  }
}

In this example we found the genre "Fantasy". We can use this in a subsequent list query by using the exact relationship field genre or _references which allows us to filter by all relationships.

{
  "filter": {
    "term": {
      "_references": "02a52a5a-aea1-4aed-9a46-799c14354a71" 
    }
  }
}


Search All content

To search all or multiple content types use the search query:

query {
  search(terms: "lewis" contentTypeNames: ["asset", "author"]) {
    results {
      _id
      __typename
      searchSummary
    }
  }
}

Join us

Interested in joining the team as coworker or investor?

contact@takeshape.com