Skip to content
Simon edited this page Jul 19, 2016 · 5 revisions

texthtml vs application/vnd.api+json requests

The file routes/search.js is the first entry point to manage a /search url request. The role of this file is to differentiate between a request coming from a user browser (Accept header is equal to "text/html") or a api request (Accept header is equal to "application/vnd.api+json"). The plugin hapi-negotiator is used to differentiate these two kind of requests.

After differentiating the requests Joi is validating the query parameters values (see the validation section). If everything is ok an object representing the request of the user is created

queryParams object

The file lib/query-params build the object representing a search request. Most of the properties of the object represent the filters. All the filter values are represented by an array. The queryParam object has the following structure:

{
  query: // the query parameters of the search request
  q: // the value search for
  pageNumber: // the current page
  pageSize: // 50 or 100 results displayed
  type: // all, people, objects or documents
  filter: {
    all: {} // the all filter values
    people: {} // the people filter values
    objects: {} // the objects filter values
    documents: {} // the documents filter values
 }
}

filter exemple:

{
  filter: {
    people: {
      birthPlace: ['Greater London, England, United Kingdom'],
      birthDate: Wed Jan 01 1800 00:00:00 GMT+0000 (GMT)
  }
  }
}

Note that only the properties date are not included in an array.

Once the queryParams object is created the lib.search.js function is called to create the elasticsearch request (see aggregation and search section). The result of the search is then transform into a json response object.

Clone this wiki locally