Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Initial entity search api (#114)
Browse files Browse the repository at this point in the history
* initial entity search api

* remove console.log

* limit and offset result
  • Loading branch information
Henni authored and syncall committed Apr 23, 2017
1 parent 98d3f7c commit 77b8297
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 39 deletions.
11 changes: 9 additions & 2 deletions api/controllers/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var context = require('../../database.js').getContext();
var search = require('../dsap/search.js')(context);

module.exports = {
searchEntities: searchEntities,
Expand All @@ -9,8 +10,14 @@ module.exports = {
};

function searchEntities(req, res) {
res.status(501);
res.json('Not implemented!');
const query = req.swagger.params.q.value;
const limit = req.swagger.params.limit.value;
const offset = req.swagger.params.offset.value;
search.searchEntities(query, limit, offset).then(function(list) {
res.status(200).json(list);
}).catch(function(error) {
res.status(500).send(error);
});
}

function searchRelations(req, res) {
Expand Down
53 changes: 53 additions & 0 deletions api/dsap/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
module.exports = function (context) {
const models = context.models;

return {
searchEntities: function(searchString, limit, offset) {
const artistsSearch = models.artists.findAll({
where: {
name: {
$like: '%' + searchString + '%'
}
},
order: [['id', 'DESC']],
limit: limit,
offset: offset
}).then((results) => {
return { artists: results }
});

const instrumentsSearch = models.instruments.findAll({
where: {
name: {
$like: '%' + searchString + '%'
}
},
order: [['id', 'DESC']],
limit: limit,
offset: offset
}).then((results) => {
return { instruments: results }
});

const releasesSearch = models.releases.findAll({
where: {
title: {
$like: '%' + searchString + '%'
}
},
order: [['id', 'DESC']],
limit: limit,
offset: offset
}).then((results) => {
return { releases: results }
});

return Promise.all([
artistsSearch, instrumentsSearch, releasesSearch
]).then(function(result) {
return result;
});
}
}
};
31 changes: 0 additions & 31 deletions api/swagger/src/definitions/definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,6 @@ Artist:
type: string
name:
type: string
artist_type:
type: string
dateOfBirth :
type: string
format: date
placeOfBirth :
type: string
dateOfDeath :
type: string
format: date
placeOfDeath :
type: string
nationality:
type: string
tags:
type: array
items:
type: string
pseudonym:
type: array
items:
type: string
source_link:
type: string
wiki_link:
type: string
wiki_pageid:
type: string

UpdateArtist:
properties:
Expand Down Expand Up @@ -139,9 +111,6 @@ Work:
type: string
title:
type: string
compositionyear:
type: integer
format: int32

UpdateWork:
properties:
Expand Down
19 changes: 13 additions & 6 deletions api/swagger/src/paths/search/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ get:
description: Returns entities matching the search criteria
operationId: searchEntities
parameters:
- name: subjectName
- name: q
in: query
description: The name of the subject
description: Query string
required: true
type: string
- name: relationName
- name: offset
in: query
description: The name of the relation
required: true
type: string
description: Return results after a certain point
required: false
type: integer
format: int32
- name: limit
in: query
description: Only return (size) entries
required: false
type: integer
format: int32
responses:
"200":
description: Success
Expand Down

0 comments on commit 77b8297

Please sign in to comment.