fuzzy search

This commit is contained in:
Drew Ansbacher
2021-09-30 11:41:28 -06:00
committed by Matt Hill
parent 357b59fd43
commit 9e6fb131ed
4 changed files with 93 additions and 21 deletions

38
ui/package-lock.json generated
View File

@@ -19,6 +19,7 @@
"@start9labs/emver": "0.1.5", "@start9labs/emver": "0.1.5",
"ajv": "^6.12.6", "ajv": "^6.12.6",
"core-js": "^3.17.2", "core-js": "^3.17.2",
"fuse.js": "^6.4.6",
"json-pointer": "^0.6.1", "json-pointer": "^0.6.1",
"jsonpointerx": "^1.1.4", "jsonpointerx": "^1.1.4",
"marked": "3.0.2", "marked": "3.0.2",
@@ -6842,6 +6843,14 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true "dev": true
}, },
"node_modules/fuse.js": {
"version": "6.4.6",
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-6.4.6.tgz",
"integrity": "sha512-/gYxR/0VpXmWSfZOIPS3rWwU8SHgsRTwWuXhyb2O6s7aRuVtHtxCkR33bNYu3wyLyNx/Wpv0vU7FZy8Vj53VNw==",
"engines": {
"node": ">=10"
}
},
"node_modules/gauge": { "node_modules/gauge": {
"version": "2.7.4", "version": "2.7.4",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
@@ -16942,7 +16951,9 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"core-js": { "core-js": {
"version": "3.16.0", "version": "3.16.0",
@@ -17089,7 +17100,9 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "1.0.0", "version": "1.0.0",
@@ -17133,7 +17146,9 @@
"integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==", "integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==",
"dev": true, "dev": true,
"peer": true, "peer": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "1.0.0", "version": "1.0.0",
@@ -17186,7 +17201,9 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "1.0.0", "version": "1.0.0",
@@ -17264,7 +17281,9 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "1.0.0", "version": "1.0.0",
@@ -18908,7 +18927,9 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": {} "requires": {
"ajv": "^8.0.0"
}
}, },
"json-schema-traverse": { "json-schema-traverse": {
"version": "1.0.0", "version": "1.0.0",
@@ -21949,6 +21970,11 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true "dev": true
}, },
"fuse.js": {
"version": "6.4.6",
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-6.4.6.tgz",
"integrity": "sha512-/gYxR/0VpXmWSfZOIPS3rWwU8SHgsRTwWuXhyb2O6s7aRuVtHtxCkR33bNYu3wyLyNx/Wpv0vU7FZy8Vj53VNw=="
},
"gauge": { "gauge": {
"version": "2.7.4", "version": "2.7.4",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",

View File

@@ -23,6 +23,7 @@
"@start9labs/emver": "0.1.5", "@start9labs/emver": "0.1.5",
"ajv": "^6.12.6", "ajv": "^6.12.6",
"core-js": "^3.17.2", "core-js": "^3.17.2",
"fuse.js": "^6.4.6",
"json-pointer": "^0.6.1", "json-pointer": "^0.6.1",
"jsonpointerx": "^1.1.4", "jsonpointerx": "^1.1.4",
"marked": "3.0.2", "marked": "3.0.2",

View File

@@ -74,6 +74,13 @@
<!-- packages loaded --> <!-- packages loaded -->
<ng-template #pkgsLoaded> <ng-template #pkgsLoaded>
<div
class="ion-padding"
*ngIf="!pkgs.length && category ==='updates'"
style="text-align: center;"
>
<h1>👏👏👏 Up to date! 👏👏👏</h1>
</div>
<ion-grid> <ion-grid>
<ion-row> <ion-row>
<ion-col *ngIf="marketplaceService.eos && category === 'featured'" sizeXs="12" sizeSm="12" sizeMd="6"> <ion-col *ngIf="marketplaceService.eos && category === 'featured'" sizeXs="12" sizeSm="12" sizeMd="6">

View File

@@ -8,6 +8,7 @@ import { Subscription } from 'rxjs'
import { ErrorToastService } from 'src/app/services/error-toast.service' import { ErrorToastService } from 'src/app/services/error-toast.service'
import { MarketplaceService } from '../marketplace.service' import { MarketplaceService } from '../marketplace.service'
import { PatchDbService } from 'src/app/services/patch-db/patch-db.service' import { PatchDbService } from 'src/app/services/patch-db/patch-db.service'
import Fuse from 'fuse.js/dist/fuse.min.js'
@Component({ @Component({
selector: 'marketplace-list', selector: 'marketplace-list',
@@ -103,23 +104,60 @@ export class MarketplaceListPage {
const { id, version } = pkg.manifest const { id, version } = pkg.manifest
return this.localPkgs[id] && version !== this.localPkgs[id].manifest.version return this.localPkgs[id] && version !== this.localPkgs[id].manifest.version
}) })
} else if (this.query) {
const options = {
isCaseSensitive: false,
includeScore: true,
shouldSort: true,
includeMatches: false,
findAllMatches: false,
minMatchCharLength: 1,
location: 0,
threshold: 0.6,
distance: 100,
useExtendedSearch: false,
ignoreLocation: false,
ignoreFieldNorm: false,
keys: [
'manifest.id',
'manifest.title',
'manifest.description.short',
'manifest.description.long',
],
}
const fuse = new Fuse(this.marketplaceService.pkgs, options)
this.pkgs = fuse.search(this.query).map(p => p.item)
} else { } else {
this.pkgs = this.marketplaceService.pkgs.filter(pkg => { const options = {
const { id, title, description } = pkg.manifest isCaseSensitive: false,
if (this.query) { includeScore: true,
const query = this.query.toUpperCase() shouldSort: true,
return id.toUpperCase().includes(query) || includeMatches: false,
title.toUpperCase().includes(query) || findAllMatches: false,
description.short.toUpperCase().includes(query) || minMatchCharLength: 1,
description.long.toUpperCase().includes(query) location: 0,
} else { threshold: 1,
if (this.category === 'all' || !this.category) { distance: 100,
return true useExtendedSearch: false,
} else { ignoreLocation: false,
return pkg.categories.includes(this.category) ignoreFieldNorm: false,
} keys: [
} 'manifest.id',
'manifest.title',
'manifest.description.short',
'manifest.description.long',
],
}
const pkgsToSort = this.marketplaceService.pkgs.filter(p => {
if (this.category === 'all') return true
return p.categories.includes(this.category)
}) })
const fuse = new Fuse(pkgsToSort, options)
this.pkgs = fuse.search(this.category !== 'all' ? this.category : 'bit').map(p => p.item)
} }
} }
} }