Skip to content

Commit

Permalink
Update singleKeywordSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieulemieux committed Nov 9, 2023
1 parent af3e76e commit 94f9034
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
38 changes: 28 additions & 10 deletions src/repo/query_builder/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const similarTo = ({
if (!edges.length) {
throw new ValidationError('Must specify 1 or more edge types to follow');
}
if (Object.keys(rest).length) {
if (Object.keys(rest).length && !(Object.keys(rest).length === 1 && rest.limit)) {
throw new ValidationError(`unrecognized arguments (${Object.keys(rest).join(', ')})`);
}
if (Array.isArray(target)) {
Expand Down Expand Up @@ -314,6 +314,7 @@ const singleKeywordSearch = ({
prefix = '',
operator = OPERATORS.CONTAINSTEXT,
targetQuery,
limit,
...opt
}) => {
const model = schemaDefn.get(target);
Expand All @@ -328,10 +329,12 @@ const singleKeywordSearch = ({
} if (schemaDefn.inheritsFrom(model.name, 'Ontology') || model.name === 'Ontology' || model.name === 'Evidence') {
return `SELECT *
FROM ${targetQuery || model.name}
WHERE name ${operator} :${param}
OR sourceId ${operator} :${param}`;
WHERE name.asString() ${operator} :${param}
OR sourceId.asString() ${operator} :${param}
LIMIT ${limit}`;
} if (model.name === 'Statement') {
const ontologySubq = singleKeywordSearch({
limit,
...opt,
operator,
param,
Expand All @@ -340,6 +343,7 @@ const singleKeywordSearch = ({
});

const variantSubq = singleKeywordSearch({
limit,
...opt,
operator,
param,
Expand Down Expand Up @@ -368,25 +372,39 @@ const singleKeywordSearch = ({
`;
return query;
} if (schemaDefn.inheritsFrom(model.name, 'Variant') || model.name === 'Variant') {
const subquery = singleKeywordSearch({
const subqueryFeature = singleKeywordSearch({
limit,
...opt,
operator,
param,
prefix: `${prefix}ontologySubq`,
target: 'Ontology',
target: 'Feature',
});
const subqueryVocab = singleKeywordSearch({
limit,
...opt,
operator,
param,
prefix: `${prefix}ontologySubq`,
target: 'Vocabulary',
});

return `SELECT expand($${prefix}variants)
LET $${prefix}ont = (
${subquery}
LET $${prefix}ontFeature = (
${subqueryFeature}
),
$${prefix}ontVocab = (
${subqueryVocab}
),
$${prefix}variants = (
SELECT *
FROM ${targetQuery || model.name}
WHERE
type IN (SELECT expand($${prefix}ont))
OR reference1 IN (SELECT expand($${prefix}ont))
OR reference2 IN (SELECT expand($${prefix}ont))
type IN (SELECT expand($${prefix}ontVocab))
OR reference1 IN (SELECT expand($${prefix}ontFeature))
OR reference2 IN (SELECT expand($${prefix}ontFeature))
OR displayName.toLowerCase() ${operator} :${param}
LIMIT ${limit}
)
`;
}
Expand Down
7 changes: 4 additions & 3 deletions src/repo/query_builder/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { RecordID: RID } = require('orientjs');

const { ValidationError, schema, util } = require('@bcgsc-pori/graphkb-schema');

const { OPERATORS, PARAM_PREFIX } = require('./constants');
const { MAX_LIMIT, OPERATORS, PARAM_PREFIX } = require('./constants');
const { FixedSubquery } = require('./fixed');
const { getQueryableProps } = require('./util');

Expand Down Expand Up @@ -380,6 +380,7 @@ class Subquery {
static parse({
target: rawTarget,
history = false,
limit = MAX_LIMIT,
filters: rawFilters = null,
queryType,
model: inputModel,
Expand Down Expand Up @@ -456,11 +457,11 @@ class Subquery {
if (queryType) {
if (!filters) {
return FixedSubquery.parse({
...rest, history, queryType, target,
...rest, history, limit, queryType, target,
}, this.parse.bind(this)); // has to be passed to avoid circular dependency
}
return FixedSubquery.parse({
...rest, filters, history, queryType, target,
...rest, filters, history, limit, queryType, target,
}, this.parse.bind(this)); // has to be passed to avoid circular dependency
}
return new this({
Expand Down
2 changes: 1 addition & 1 deletion src/repo/query_builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WrapperQuery {
} = checkStandardOptions(opt);

const query = Subquery.parse({
history, model: inputModel, target, ...rest,
history, limit, model: inputModel, target, ...rest,
});
const model = schemaDefn.get(inputModel, false) || schemaDefn.get(target, false) || schemaDefn.models.V;

Expand Down

0 comments on commit 94f9034

Please sign in to comment.