Skip to content

Commit 122f36e

Browse files
Case insensitive animal history search
- If caseInsensitive is true, use CONTAINS filter when querying for valid animal Ids which is case insensitive for PG (MSSQL always case insensitive). Then do lowercase match on Ids and possible aliases.
2 parents 6f792f6 + ec38813 commit 122f36e

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

LDK/resources/web/LDK/panel/SingleSubjectFilterType.js

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
99

1010
nounSingular: 'Subject',
1111

12+
// This flag updates alias/Id db query to use a case insensitive LK filter (CONTAINS). The
13+
// results are processed after to do case insensitive matches on the results with the user entered Ids.
14+
// This is primarily for use when an alias table is set for the filter.
15+
caseInsensitive: false,
16+
1217
subjects: [],
1318
notFound: [],
1419
aliases: {},
@@ -155,7 +160,12 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
155160

156161
aliasTableConfig: function (subjectArray) {
157162
this.aliasTable.scope = this;
158-
this.aliasTable.filterArray = [LABKEY.Filter.create('alias', subjectArray.join(';'), LABKEY.Filter.Types.EQUALS_ONE_OF)];
163+
164+
// When caseInsensitive is true, use contains filter to ensure case insensitivity across dbs. This will return more
165+
// results than necessary in some cases, however those results are filtered to match the user input and non-matching
166+
// results are not used.
167+
var filterType = this.caseInsensitive ? LABKEY.Filter.Types.CONTAINS_ONE_OF : LABKEY.Filter.Types.EQUALS_ONE_OF;
168+
this.aliasTable.filterArray = [LABKEY.Filter.create('alias', subjectArray.join(';'), filterType)];
159169
this.aliasTable.columns = this.aliasTable.idColumn + (Ext4.isDefined(this.aliasTable.aliasColumn) ? ',' + this.aliasTable.aliasColumn : '');
160170
},
161171

@@ -179,16 +189,38 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
179189

180190
// Remove from notFound array if found
181191
var subjIndex = this.notFound.indexOf(row[this.aliasTable.aliasColumn]);
182-
if (subjIndex != -1) {
192+
if (subjIndex === -1 && this.caseInsensitive) {
193+
for (var i = 0; i < this.notFound.length; i++) {
194+
if (row[this.aliasTable.aliasColumn].toLowerCase() === this.notFound[i].toString().toLowerCase()) {
195+
subjIndex = i;
196+
break;
197+
}
198+
}
199+
}
200+
201+
if (subjIndex !== -1) {
183202
this.notFound.splice(subjIndex, 1);
184203
}
185204

205+
var index = this.subjects.indexOf(row[this.aliasTable.aliasColumn]);
206+
if (index === -1 && this.caseInsensitive) {
207+
for (var i = 0; i < this.subjects.length; i++) {
208+
if (row[this.aliasTable.aliasColumn].toLowerCase() === this.subjects[i].toString().toLowerCase()) {
209+
index = i;
210+
break;
211+
}
212+
}
213+
}
214+
215+
if (index !== -1) {
216+
this.subjects.splice(index, 1, row[this.aliasTable.idColumn]);
217+
}
218+
186219
// Resolve aliases
187-
if (row[this.aliasTable.idColumn] != row[this.aliasTable.aliasColumn]) {
188-
var index = this.subjects.indexOf(row[this.aliasTable.aliasColumn]);
189-
if (index != -1) {
220+
if (row[this.aliasTable.idColumn] !== row[this.aliasTable.aliasColumn]) {
221+
222+
if (index !== -1) {
190223
this.aliases[row[this.aliasTable.aliasColumn]] = [row[this.aliasTable.idColumn]];
191-
this.subjects.splice(index, 1, row[this.aliasTable.idColumn]);
192224
}
193225
// In case an alias matches multiple ID's
194226
else {
@@ -205,11 +237,19 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
205237
else {
206238
// Remove from notFound array if found
207239
var idIndex = this.notFound.indexOf(row[this.aliasTable.idColumn]);
240+
if (idIndex === -1 && this.caseInsensitive) {
241+
for (var i = 0; i < this.notFound.length; i++) {
242+
if (row[this.aliasTable.idColumn].toLowerCase() === this.notFound[i].toString().toLowerCase()) {
243+
idIndex = i;
244+
break;
245+
}
246+
}
247+
}
208248

209249
// TODO: Update this and LDK.Utils.splitIds when the case sensitive cache issues are fixed
210250
if (idIndex == -1) {
211251
for (var nfIndex = 0; nfIndex < this.notFound.length; nfIndex++) {
212-
if (this.notFound[nfIndex].toUpperCase() == row[this.aliasTable.idColumn]) {
252+
if (this.notFound[nfIndex].toString().toUpperCase() == row[this.aliasTable.idColumn]) {
213253
idIndex = nfIndex;
214254
break;
215255
}

0 commit comments

Comments
 (0)