Skip to content

Commit

Permalink
Support #32023 - Test partial search
Browse files Browse the repository at this point in the history
- Contains should use the case_insensitive option. It's now being set to true.
- Added test coverage for wildcards.
- Updated more snapshots.
  • Loading branch information
brandonandre committed Oct 4, 2023
1 parent cf57461 commit 25d7e6e
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export function wildcardQuery(fieldName: string, matchValue: any, keywordSupport
return {
wildcard: {
[keywordSupport ? fieldName + ".keyword" : fieldName]: {
value: `*${matchValue}*`
value: `*${matchValue}*`,
case_insensitive: true
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ exports[`QueryBuilderElasticSearchExport functionality Query helper functions wi
Object {
"wildcard": Object {
"fieldTest": Object {
"case_insensitive": true,
"value": "*valueToMatch*",
},
},
Expand All @@ -238,6 +239,7 @@ exports[`QueryBuilderElasticSearchExport functionality Query helper functions wi
Object {
"wildcard": Object {
"fieldTest.keyword": Object {
"case_insensitive": true,
"value": "*valueToMatch*",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,62 @@ describe("QueryBuilderTextSearch", () => {
});
});

describe("contains (wildcard) operation", () => {
test("With relationship as field", async () => {
expect(
transformTextSearchToDSL({
operation: "wildcard",
value: "text search",
fieldInfo: {
label: "name",
value: "collection.name",
type: "text",
path: "attributes",
parentName: "collection",
parentType: "collection",
parentPath: "included",
distinctTerm: true,
keywordMultiFieldSupport: true
} as any,
fieldPath: "included.attributes.name",
queryType: "wildcard"
})
).toMatchSnapshot();
});

test("With relationship containing complex path as field", async () => {
expect(
transformTextSearchToDSL({
operation: "wildcard",
value: "text",
fieldInfo: {
label: "determination.scientificName",
parentName: "organism",
parentPath: "included",
parentType: "organism",
path: "attributes.determination",
type: "text",
value: "organism.determination.scientificName"
} as any,
fieldPath: "included.attributes.determination.scientificName",
queryType: "wildcard"
})
).toMatchSnapshot();
});

test("Normal field", async () => {
expect(
transformTextSearchToDSL({
operation: "wildcard",
value: "text search",
fieldInfo: {} as any,
fieldPath: "data.attributes.textField",
queryType: "wildcard"
})
).toMatchSnapshot();
});
});

describe("ContainsText (Infix) operation", () => {
test("With relationship as field", async () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ exports[`QueryBuilderManagedAttributeSearch transformFieldExtensionToDSL functio
Object {
"wildcard": Object {
"data.attributes.extensionValues.extension.field.keyword": Object {
"case_insensitive": true,
"value": "*test123*",
},
},
Expand Down Expand Up @@ -316,6 +317,7 @@ Object {
Object {
"wildcard": Object {
"included.attributes.extensionValues.extension.field.keyword": Object {
"case_insensitive": true,
"value": "*test123*",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ exports[`QueryBuilderManagedAttributeSearch transformManagedAttributeToDSL funct
Object {
"wildcard": Object {
"data.attributes.managedAttributes.attributeName.keyword": Object {
"case_insensitive": true,
"value": "*stringValue*",
},
},
Expand Down Expand Up @@ -1827,6 +1828,7 @@ Object {
Object {
"wildcard": Object {
"included.attributes.managedAttributes.attributeName.keyword": Object {
"case_insensitive": true,
"value": "*stringValue*",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,71 @@ Object {
}
`;

exports[`QueryBuilderTextSearch transformTextSearchToDSL function contains (wildcard) operation Normal field 1`] = `
Object {
"wildcard": Object {
"data.attributes.textField": Object {
"case_insensitive": true,
"value": "*text search*",
},
},
}
`;

exports[`QueryBuilderTextSearch transformTextSearchToDSL function contains (wildcard) operation With relationship as field 1`] = `
Object {
"nested": Object {
"path": "included",
"query": Object {
"bool": Object {
"must": Array [
Object {
"wildcard": Object {
"included.attributes.name.keyword": Object {
"case_insensitive": true,
"value": "*text search*",
},
},
},
Object {
"term": Object {
"included.type": "collection",
},
},
],
},
},
},
}
`;

exports[`QueryBuilderTextSearch transformTextSearchToDSL function contains (wildcard) operation With relationship containing complex path as field 1`] = `
Object {
"nested": Object {
"path": "included",
"query": Object {
"bool": Object {
"must": Array [
Object {
"wildcard": Object {
"included.attributes.determination.scientificName": Object {
"case_insensitive": true,
"value": "*text*",
},
},
},
Object {
"term": Object {
"included.type": "organism",
},
},
],
},
},
},
}
`;

exports[`QueryBuilderTextSearch transformTextSearchToDSL function startsWith (prefix) operation (Non-optimized) Normal field 1`] = `
Object {
"prefix": Object {
Expand Down

0 comments on commit 25d7e6e

Please sign in to comment.