Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve search mechanism #510

Merged
merged 7 commits into from
Nov 16, 2021
Merged
5 changes: 3 additions & 2 deletions packages/solid-crs-core/lib/utils/fulltext-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ export const fulltextMatch = (object: unknown, term: string): boolean => {
}

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

return !!Object.values(object)
.map((value) => {

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

return value.toLowerCase().includes(term.toLowerCase());
return splitTerm.every((t: string) => value.toLowerCase().includes(t));

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

return value.toString().includes(lowercaseTerm);
return splitTerm.every((t: string) => value.toString().toLowerCase().includes(t));

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

Expand Down
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.14
}
},
"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 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { map } from 'rxjs/operators';
import { from } from 'rxjs';
import { Interpreter, State } from 'xstate';
import { RxLitElement } from 'rx-lit';
import { Connect, Dots, Identity, Image, Object as ObjectIcon, Download, Theme, Cross, Open } from '@netwerk-digitaal-erfgoed/solid-crs-theme';
import { Connect, Dots, Identity, Image, Object as ObjectIcon, Theme, Cross, Open } from '@netwerk-digitaal-erfgoed/solid-crs-theme';
import { unsafeSVG } from 'lit-html/directives/unsafe-svg';
import { fetch as solidFetch } from '@netwerk-digitaal-erfgoed/solid-crs-client';
import { AddAlertEvent, DismissAlertEvent } from '../../app.events';
import { SelectedCollectionEvent } from '../collection/collection.events';
import { ObjectContext } from './object.machine';
Expand Down Expand Up @@ -132,9 +133,28 @@ export class ObjectRootComponent extends RxLitElement {
const alerts = this.alerts?.map((alert) => html`<nde-alert .logger='${this.logger}' .translator='${this.translator}' .alert='${alert}' @dismiss="${this.handleDismiss}"></nde-alert>`);
const collection = this.collections?.find((coll) => coll.uri === this.object?.collection);

const toggleImage = () => { this.imagePopup.toggle(); };
const toggleImage = () => { this.imagePopup.toggle(); };

const toggleInfo = () => { this.infoPopup.toggle(); };
const toggleInfo = () => { this.infoPopup.toggle(); };

const downloadRDF = () => {

solidFetch(this.object?.uri)
.then((response) => response.blob())
.then((blob) => {

const blobURL = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = blobURL;
const slashSplit = this.object?.uri.split('/');
a.download = `${slashSplit[slashSplit.length - 1]}.ttl`;
(a as any).style = 'display: none';
document.body.appendChild(a);
a.click();

});

};

return this.object ? html`

Expand All @@ -151,7 +171,7 @@ export class ObjectRootComponent extends RxLitElement {
${ unsafeSVG(Dots) }
<nde-popup id="info-popup">
<div slot="content">
<a target="_blank" rel="noopener noreferrer" href="${this.object.uri}">
<a @click="${downloadRDF}">
${this.translator.translate('object.root.menu.view-rdf')}
</a>
</div>
Expand Down
8 changes: 4 additions & 4 deletions packages/solid-crs-presentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
],
"coverageThreshold": {
"global": {
"statements": 87.06,
"statements": 85.95,
"branches": 83.59,
"lines": 88.2,
"functions": 71.72
"lines": 86.98,
"functions": 72.14
}
},
"automock": false,
Expand All @@ -111,4 +111,4 @@
}
}
}
}
}