mirror of
https://github.com/ivabus/www
synced 2024-11-22 07:15:07 +03:00
Merge pull request #307 from teaxyz/search-adjustments
#294 improve search exact match
This commit is contained in:
commit
d1b7ccfcad
2 changed files with 9 additions and 6 deletions
|
@ -121,11 +121,13 @@
|
||||||
if (searchInput.value) {
|
if (searchInput.value) {
|
||||||
const term = searchInput.value;
|
const term = searchInput.value;
|
||||||
const packages = getPackageThumbs();
|
const packages = getPackageThumbs();
|
||||||
|
for(let pkg of packages) {
|
||||||
|
pkg.match_score = getMatchScore(term, pkg.dataset);
|
||||||
|
}
|
||||||
const sortedPackages = packages.sort((a, b) => {
|
const sortedPackages = packages.sort((a, b) => {
|
||||||
const aScore = getMatchScore(term, a.dataset);
|
return b.match_score - (a ? a.match_score : 0);
|
||||||
const bScore = getMatchScore(term, b.dataset);
|
|
||||||
return bScore - aScore;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const grid = document.getElementById('packageGrid');
|
const grid = document.getElementById('packageGrid');
|
||||||
grid.textContent = '';
|
grid.textContent = '';
|
||||||
let searchCount = 0;
|
let searchCount = 0;
|
||||||
|
@ -209,10 +211,11 @@
|
||||||
|
|
||||||
function getMatchScore(term, dataset) {
|
function getMatchScore(term, dataset) {
|
||||||
// provide higher value with name
|
// provide higher value with name
|
||||||
const { name, description } = dataset;
|
const { name, maintainer, description } = dataset;
|
||||||
|
const exactMatch = [maintainer, name].join(" ").toLocaleLowerCase().includes(term.toLocaleLowerCase());
|
||||||
const nameScore = stringSimilarity.compareTwoStrings(name, term);
|
const nameScore = stringSimilarity.compareTwoStrings(name, term);
|
||||||
const descriptionScore = stringSimilarity.compareTwoStrings(description, term);
|
const descriptionScore = stringSimilarity.compareTwoStrings(description, term);
|
||||||
return (nameScore*80) + (descriptionScore*20)
|
return (nameScore*80) + (descriptionScore*20) + (exactMatch ? 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadMoreButton = document.getElementById('loadMorePackagesBtn');
|
const loadMoreButton = document.getElementById('loadMorePackagesBtn');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="card card-thumbnail" style="width: 100%" data-name="{{- .name -}}" data-popularity="{{- .dl_count -}}" data-last_modified="{{- .last_modified -}}" data-description="{{- .desc -}}">
|
<div class="card card-thumbnail" style="width: 100%" data-name="{{- .name -}}" data-popularity="{{- .dl_count -}}" data-last_modified="{{- .last_modified -}}" data-description="{{- .desc -}}" data-maintainer="{{- .maintainer -}}">
|
||||||
<a href="/+{{- lower .full_name -}}/">
|
<a href="/+{{- lower .full_name -}}/">
|
||||||
<div class="p-3">
|
<div class="p-3">
|
||||||
<figure class="card-img-top" >
|
<figure class="card-img-top" >
|
||||||
|
|
Loading…
Reference in a new issue