Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/constants/structuredDateFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const EARLIEST_SCALAR_DATE_FIELD = '/dateEarliestScalarValue';
export const LATEST_SCALAR_DATE_FIELD = '/dateLatestScalarValue';
export const DISPLAY_DATE_FIELD = '/dateDisplayDate';
export const ASSOCIATION_FIELD = '/dateAssociation';
export const EARLIEST_SINGLE_YEAR_FIELD = '/dateEarliestSingleYear';
export const EARLIEST_SINGLE_MONTH_FIELD = '/dateEarliestSingleMonth';
export const EARLIEST_SINGLE_DAY_FIELD = '/dateEarliestSingleDay';
export const EARLIEST_SINGLE_ERA_FIELD = '/dateEarliestSingleEra';
export const EARLIEST_SINGLE_CERTAINTY_FIELD = '/dateEarliestSingleCertainty';
export const EARLIEST_SINGLE_QUALIFIER_FIELD = '/dateEarliestSingleQualifier';
export const EARLIEST_SINGLE_QUALIFIER_VALUE_FIELD = '/dateEarliestSingleQualifierValue';
export const EARLIEST_SINGLE_QUALIFIER_UNIT_FIELD = '/dateEarliestSingleQualifierUnit';
export const LATEST_YEAR_FIELD = '/dateLatestYear';
export const LATEST_MONTH_FIELD = '/dateLatestMonth';
export const LATEST_DAY_FIELD = '/dateLatestDay';
export const LATEST_ERA_FIELD = '/dateLatestEra';
export const LATEST_CERTAINTY_FIELD = '/dateLatestCertainty';
export const LATEST_QUALIFIER_FIELD = '/dateLatestQualifier';
export const LATEST_QUALIFIER_VALUE_FIELD = '/dateLatestQualifierValue';
export const LATEST_QUALIFIER_UNIT_FIELD = '/dateLatestQualifierUnit';
export const PERIOD_FIELD = '/datePeriod';
export const NOTE_FIELD = '/dateNote';

export const ALL_FIELDS = [
EARLIEST_SCALAR_DATE_FIELD,
LATEST_SCALAR_DATE_FIELD,
DISPLAY_DATE_FIELD,
ASSOCIATION_FIELD,
EARLIEST_SINGLE_YEAR_FIELD,
EARLIEST_SINGLE_MONTH_FIELD,
EARLIEST_SINGLE_DAY_FIELD,
EARLIEST_SINGLE_ERA_FIELD,
EARLIEST_SINGLE_CERTAINTY_FIELD,
EARLIEST_SINGLE_QUALIFIER_FIELD,
EARLIEST_SINGLE_QUALIFIER_VALUE_FIELD,
EARLIEST_SINGLE_QUALIFIER_UNIT_FIELD,
LATEST_YEAR_FIELD,
LATEST_MONTH_FIELD,
LATEST_DAY_FIELD,
LATEST_ERA_FIELD,
LATEST_CERTAINTY_FIELD,
LATEST_QUALIFIER_FIELD,
LATEST_QUALIFIER_VALUE_FIELD,
LATEST_QUALIFIER_UNIT_FIELD,
PERIOD_FIELD,
NOTE_FIELD,
];
37 changes: 35 additions & 2 deletions src/helpers/searchHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ import {
import {
NS_PREFIX,
} from '../constants/xmlNames';
import {
ALL_FIELDS,
EARLIEST_SCALAR_DATE_FIELD,
LATEST_SCALAR_DATE_FIELD,
} from '../constants/structuredDateFields';

const opsByDataTypeMapNew = {
[DATA_TYPE_STRING]: [
Expand Down Expand Up @@ -645,6 +650,10 @@ export const booleanConditionToNXQL = (fieldDescriptor, condition, counter) => {

const correlatePath = (nxql, nxqlPath, counter) => {
if (!nxqlPath.endsWith('*')) {
if (nxqlPath.includes('*')) {
const index = nxqlPath.lastIndexOf('*');
return correlatePath(nxql, nxqlPath.substring(0, index + 1), counter);
}
return nxql;
}

Expand Down Expand Up @@ -684,8 +693,8 @@ export const structuredDateFieldConditionToNXQL = (fieldDescriptor, condition, c
const operator = condition.get('op');
const value = condition.get('value');

const earliestScalarDatePath = `${path}/dateEarliestScalarValue`;
const latestScalarDatePath = `${path}/dateLatestScalarValue`;
const earliestScalarDatePath = `${path}${EARLIEST_SCALAR_DATE_FIELD}`;
const latestScalarDatePath = `${path}${LATEST_SCALAR_DATE_FIELD}`;

let convertedCondition;

Expand Down Expand Up @@ -714,6 +723,30 @@ export const structuredDateFieldConditionToNXQL = (fieldDescriptor, condition, c
],
},
});
} else if (operator === OP_NULL) {
convertedCondition = Immutable.fromJS({
path,
op: OP_GROUP,
value: {
op: OP_AND,
value: ALL_FIELDS.map((field) => ({
path: `${path}${field}`,
op: OP_NULL,
})),
},
});
} else if (operator === OP_NOT_NULL) {
convertedCondition = Immutable.fromJS({
path,
op: OP_GROUP,
value: {
op: OP_OR,
value: ALL_FIELDS.map((field) => ({
path: `${path}${field}`,
op: OP_NOT_NULL,
})),
},
});
} else if (operator === OP_NOT_RANGE) {
// The structured date range does not overlap the value range.
// This will be the logical negation of OP_RANGE.
Expand Down
29 changes: 29 additions & 0 deletions test/specs/helpers/searchHelpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ describe('searchHelpers', () => {
geordi: {},
worf: {},
},
nonRepeatingNestedGroup: {
qux: {},
quux: {},
},
},
},
},
Expand Down Expand Up @@ -1024,6 +1028,31 @@ describe('searchHelpers', () => {
groupConditionToNXQL(fields, condition, createCounter()).should
.equal('(part:groupList/*2/nestedGroupList/*1/worf > "val1" OR part:groupList/*2/nestedGroupList/*1/geordi < "val2")');
});

it('should correlate paths to the fields in nested groups, when group is not repeating but parent group is', () => {
const condition = Immutable.fromJS({
op: OP_GROUP,
path: 'ns2:part/groupList/group/nestedGroupList/nonRepeatingNestedGroup',
value: {
op: OP_OR,
value: [
{
op: OP_GT,
path: 'ns2:part/groupList/group/nestedGroupList/nonRepeatingNestedGroup/qux',
value: 'val1',
},
{
op: OP_LT,
path: 'ns2:part/groupList/group/nestedGroupList/nonRepeatingNestedGroup/quux',
value: 'val2',
},
],
},
});

groupConditionToNXQL(fields, condition, createCounter()).should
.equal('(part:groupList/*1/nestedGroupList/nonRepeatingNestedGroup/qux > "val1" OR part:groupList/*1/nestedGroupList/nonRepeatingNestedGroup/quux < "val2")');
});
});

describe('rangeFieldConditionToNXQL', () => {
Expand Down