Skip to content

Search Data Structure

Tomáš Livora edited this page May 8, 2017 · 10 revisions

This document describes the structure of search queries, suggestions, and search results.

Queries

Queries, which are created by front-end and sent to back-end, have the following structure:

{
  "text": "battery electric",
  "view": "LongRangeElectricVehicles",
  "collections": ["cars", "trucks"],
  "attributes": [
    {
      "collection": "cars",
      "attribute": "range",
      "operator": ">",
      "value": 500
    }
  ],
  "links": [],
  "tab": "all",
  "sort": {
    "price": 1
  },
  "position": 0,
  "limit": 100
}

View

Specifies the view used to display the results. Although view name is shown to users in the UI, view field of a search query contains view ID. This field cannot be combined with any other field.

Collections

Contains an array of names of collections where the search will be performed.

Filter

Filters specifying conditions that needs to be satisfied by the search results. They should be similar to the MongoDB query selectors.

Text

A string of keywords which will be used in a fulltext search.

Links

An array of IDs of link types that are associated with the returned collections and documents.

Tab

The currently selected tab on the search results screen. Possible values are:

  • all
  • documents
  • collections
  • views
  • links

When the search is performed for the first time, all value is used by default.

Sort

Fields that will be used for sorting the search results. The value 1 represents ascending while -1 represents descending order.

Position

A position from which the search results will be returned. All previous results will be skipped. The default value is 0.

Limit

The number of search results returned. This field together with position supports simple pagination. The default value is 20.

Suggestions

Search suggestions, which are returned by back-end to suggest the next part of the query, have the following structure:

{
  "collections": [
    {
      "name": "cars",
      "icon": "/path/to/cars_icon.png"
    },
    {
      "name": "trucks",
      "icon": "/path/to/trucks_icon.png"
    }
  ],
  "attributes": [
    {
      "collection": "cars",
      "attribute": "range",
      "constraints": ["isNumber", "greaterThan:0"]
    }
  ],
  "views": [
    {
      "name": "electricCars",
      "icon": "/path/to/electric_cars_icon.png"
    }
  ],
  "linkTypes": [
    {
      "from": "cars",
      "to": "manufacturers",
      "role": "madeBy"
    }
  ]
}

They do not contain the whole documents or all information about collections but just the necessary information to be shown in the suggestions under the search bar.

Results

Search results, which are created by back-end and sent to front-end, have the following structure:

{
  "query": [{}, {}],
  "matched": {
    "views": [{}, {}],
    "collections": [{}, {}],
    "documents": [{}, {}],
    "links": [{}, {}]
  },
  "favorite": {
    "views": [{}, {}],
    "collections": [{}, {}],
    "documents": [{}, {}]
  },
  "recent": {
    "views": [{}, {}],
    "collections": [{}, {}],
    "documents": [{}, {}]
  }
}

The individual fields contain data only if the given search view or all search results are shown.

Query

The same object which specified the search query. In case of a query containing only the view ID, the result will contain other parameters as well so they can be shown to a user in the search bar.

Matched

Lists of all views, collections, documents, and links that match the search query.

Favorite

The most popular (by some metric) views, collections, and documents. These are only returned if the all tab is shown.

Recent

Recently used views, collections, and documents. These are only returned if the all tab is shown.

Clone this wiki locally