Skip to content

Commit

Permalink
fixed merge conflict in qparts
Browse files Browse the repository at this point in the history
  • Loading branch information
punkish committed Jul 22, 2020
2 parents c9f7d55 + 7cf6a92 commit 922eb43
Show file tree
Hide file tree
Showing 10 changed files with 1,090 additions and 311 deletions.
134 changes: 72 additions & 62 deletions api/v2/lib/dd2queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,44 @@ const dd2queries = function(queryObject) {
return q;
};

// We go through the data dictionary and create a data structure that
// groups various keys of a resource field by the related query string
// param submitted via a REST API. There is another grouping that helps
// doing a quick look up of the resourceID key for a given resource,
// for example, 'treatmentId' for 'treatments'. This is how ddKeys looks
//
// "byQueryString": {
// "treatments": {
// "treatmentId": {
// "sqlName": "treatmentId",
// "queryable": "equal",
// "table": false,
// "resourceId": "treatmentId"
// },
// "treatmentTitle": {
// "sqlName": "treatmentTitle",
// "queryable": "like",
// "table": false,
// "resourceId": false
// },
// … other fields …
// },
// … other resources …
// },
// "byResourceIds": {
// "treatments": "treatmentId",
// "figureCitations": "figureCitationId",
// "bibRefCitations": "bibRefCitationId",
// "treatmentCitations": "treatmentCitationId",
// "materialsCitations": "materialsCitationId",
// "treatmentAuthors": "treatmentAuthorId",
// "images": "id",
// "publications": "id"
// }
/*************************************************************************
We go through the data dictionary and create a data structure that
groups various keys of a resource field by the related query string
param submitted via a REST API. There is another grouping that helps
doing a quick look up of the resourceID key for a given resource,
for example, 'treatmentId' for 'treatments'. This is how ddKeys looks
"byQueryString": {
"treatments": {
"treatmentId": {
"sqlName": "treatmentId",
"queryable": "equal",
"table": false,
"resourceId": "treatmentId"
},
"treatmentTitle": {
"sqlName": "treatmentTitle",
"queryable": "like",
"table": false,
"resourceId": false
},
… other fields …
},
… other resources …
},
"byResourceIds": {
"treatments": "treatmentId",
"figureCitations": "figureCitationId",
"bibRefCitations": "bibRefCitationId",
"treatmentCitations": "treatmentCitationId",
"materialsCitations": "materialsCitationId",
"treatmentAuthors": "treatmentAuthorId",
"images": "id",
"publications": "id"
}
*************************************************************************/
const getDdKeys = function() {

const byQueryString = {};
Expand Down Expand Up @@ -227,18 +231,22 @@ const calcConstraint = function(ddKeys, queryObject) {
}
else if (op === 'between') {

// else if (col === 'lat') {
// cols.push('latitude > @min_latitude');
// cols.push('latitude < @max_latitude');
// queryObject.min_latitude = queryObject.lat - range;
// queryObject.max_latitude = +queryObject.lat + range;
// }
// else if (col === 'lon') {
// cols.push('longitude > @min_longitude');
// cols.push('longitude < @max_longitude');
// queryObject.min_longitude = queryObject.lon - range;
// queryObject.max_longitude = +queryObject.lon + range;
// }
/***********************************************************************
else if (col === 'lat') {
cols.push('latitude > @min_latitude');
cols.push('latitude < @max_latitude');
queryObject.min_latitude = queryObject.lat - range;
queryObject.max_latitude = +queryObject.lat + range;
}
else if (col === 'lon') {
cols.push('longitude > @min_longitude');
cols.push('longitude < @max_longitude');
queryObject.min_longitude = queryObject.lon - range;
queryObject.max_longitude = +queryObject.lon + range;
}
***********************************************************************/

const delta = 0.9;
queryObject[`min_${k}`] = +queryObject[k] - delta;
Expand All @@ -253,20 +261,22 @@ const calcConstraint = function(ddKeys, queryObject) {
return [ matchTables, constraint ];
};

// A query is made up of seven parts
//
// three mandatory parts
// -----------------------------
// SELECT <columns>
// FROM <tables>
// WHERE <constraint>
//
// four optional parts
// -----------------------------
// GROUP BY <group>
// ORDER BY <sortcol> <sortdir>
// LIMIT <limit>
// OFFSET <offset>
/***********************************************************************
A query is made up of seven parts
three mandatory parts
-----------------------------
SELECT <columns>
FROM <tables>
WHERE <constraint>
four optional parts
-----------------------------
GROUP BY <group>
ORDER BY <sortcol> <sortdir>
LIMIT <limit>
OFFSET <offset>
***********************************************************************/
const calcQuery = function(ddKeys, queryGroup, query, queryObject, matchTables, additionalConstraint) {

//console.log(additionalConstraint)
Expand Down Expand Up @@ -334,12 +344,12 @@ const test = function() {
// page: 1,
// size: 30,
resource: 'treatments',
author: 'fisher',
// author: 'fisher',
// facets: false,
// stats: false,
// xml: false,
// sortBy: 'journalYear:ASC',
// q: 'carabus',
q: 'Rhinolophus sinicus',
// authorityName: 'Agosti',
// journalYear: '1996',
// format: 'xml',
Expand Down
2 changes: 1 addition & 1 deletion api/v2/lib/qparts.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const queryParts = {
constraint: ['treatments.deleted = 0'],
sortBy: {
columns: [
'journalYear',
'journalYear',
'treatmentTitle'
],
defaultSort: {
Expand Down
32 changes: 27 additions & 5 deletions bin/truebug.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
'use strict';

const config = require('config');
const Utils = require('../api/v2/utils');
const opts = require('./truebug/opts')
//const download = require('./truebug/download');
const download = require('./truebug/download');
const parse = require('./truebug/parse');
const database = require('./truebug/database');
const plog = require(config.get('plog'));

let timer = process.hrtime();

// download new files zip archive
if (opts.download) {
download();
download(opts.download);
}

if (opts.database) {
database.createTables();

// tables will get created if they don't already exist
database.createTablesStatic();

// insert statements will be prepared and stored to run
// as transactions
database.createInsertStatements();
}

if (opts.parse) {
parse(opts.parse, opts.rearrange, opts.database);
}

if (opts.database) {
database.indexTables();
}
database.indexTablesStatic();
}

timer = process.hrtime(timer);
plog.logger({
host: 'localhost',
start: 'start',
end: 'end',
status: 200,
resource: 'parse',
query: `parsed`,
message: Utils.timerFormat(timer)
});
Loading

0 comments on commit 922eb43

Please sign in to comment.