Skip to content

Commit

Permalink
fix: improve object search algorithm (#510)
Browse files Browse the repository at this point in the history
* feat: improve search mechanism

* feat: download collection object .ttl files (#509)

* feat: download rdf ttl file

* fix: changed default fetch for solid fetch

* fix: adapted search algorithm to achieve desired outcome
  • Loading branch information
BelgianNoise authored Nov 16, 2021
1 parent 652cf8d commit 7203f51
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('CollectionObjectMemoryStore', () => {
{
uri: 'object-uri-1',
name: 'Object 1',
description: 'This is object 1',
description: 'This is object 1 something new',
image: null,
subject: null,
type: null,
Expand All @@ -26,7 +26,7 @@ describe('CollectionObjectMemoryStore', () => {
{
uri: 'object-uri-2',
name: 'Object 2',
description: 'This is object 2',
description: 'This is object 2 added characters',
image: null,
subject: null,
type: null,
Expand All @@ -36,7 +36,7 @@ describe('CollectionObjectMemoryStore', () => {
{
uri: 'object-uri-3',
name: 'Object 3',
description: 'This is object 3',
description: 'This is object 3 and some extra filler text',
image: null,
subject: null,
type: null,
Expand Down Expand Up @@ -123,13 +123,13 @@ describe('CollectionObjectMemoryStore', () => {

it('should return the correct object', async () => {

await expect(service.search('Object 1', resources)).resolves.toEqual([ resources[0] ]);
await expect(service.search('collection something', resources)).resolves.toEqual([ resources[0] ]);

});

it('should return the correct objects', async () => {

await expect(service.search('Object 2', resources)).resolves.toEqual([ resources[1] ]);
await expect(service.search('uri extra', resources)).resolves.toEqual([ resources[2] ]);

});

Expand Down
30 changes: 15 additions & 15 deletions packages/solid-crs-core/lib/utils/fulltext-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ export const fulltextMatch = (object: unknown, term: string): boolean => {

}

const lowercaseTerm: string = term.toLowerCase();
const lowercaseTerm: string = term.toLowerCase().trim();
const splitTerm: string[] = lowercaseTerm.split(' ');

return !!Object.values(object)
.map((value) => {
return splitTerm.every((termPart: string) => Object.values(object).some((value: any) => {

if (typeof value === 'string' || value instanceof String) {
if (typeof value === 'string' || value instanceof String) {

return value.toLowerCase().includes(term.toLowerCase());
return value.toLowerCase().includes(termPart);

} else if (typeof value === 'number' || value instanceof Number) {
} else if (typeof value === 'number' || value instanceof Number) {

return value.toString().includes(lowercaseTerm);
return value.toString().toLowerCase().includes(termPart);

} else if (value instanceof Array && value.length > 0) {
} else if (value instanceof Array && value.length > 0) {

return !!value.find((element) => fulltextMatch({ key: element }, lowercaseTerm));
return value.some((element) => fulltextMatch({ key: element }, termPart));

} else if (typeof value === 'object' || value instanceof Object) {
} else if (typeof value === 'object' || value instanceof Object) {

return fulltextMatch(value, lowercaseTerm);
return fulltextMatch(value, termPart);

} else {
} else {

return false;
return false;

}
}

}).find((value) => value === true);
}));

};
8 changes: 4 additions & 4 deletions packages/solid-crs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
],
"coverageThreshold": {
"global": {
"statements": 98,
"statements": 98.01,
"branches": 94.55,
"lines": 97.91,
"functions": 98.09
"lines": 97.92,
"functions": 98.11
}
},
"automock": false,
Expand All @@ -101,4 +101,4 @@
"displayName": "core",
"preset": "@digita-ai/jest-config"
}
}
}
10 changes: 5 additions & 5 deletions packages/solid-crs-manage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
],
"coverageThreshold": {
"global": {
"statements": 89.39,
"branches": 85.31,
"lines": 90.08,
"functions": 80.12
"statements": 89.4,
"branches": 86.09,
"lines": 90.09,
"functions": 80.49
}
},
"automock": false,
Expand All @@ -112,4 +112,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/solid-crs-presentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
}
}
}
}
}

0 comments on commit 7203f51

Please sign in to comment.