Skip to content

Commit

Permalink
Merge pull request #2043 from laws-africa/best-match
Browse files Browse the repository at this point in the history
highligh best search result if it's score is better than the 2nd result
  • Loading branch information
longhotsummer authored Sep 17, 2024
2 parents 0ee205c + 570ab3a commit b0f218e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions peachjam/js/components/FindDocuments/SearchResult.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<li class="mb-4 hit">
<div class="card">
<li :class="`mb-4 hit ${item.best_match ? 'best-match' : ''}`">
<div class="card" :data-best-match="$t('Best match')">
<div class="card-body">
<h5 class="card-title">
<a
Expand Down Expand Up @@ -183,4 +183,19 @@ export default {
max-height: 50vh;
overflow-y: auto;
}
.hit.best-match .card {
box-shadow: 0px 0px 5px 2px gold;
}
.hit.best-match .card::before {
content: attr(data-best-match);
position: absolute;
background: gold;
padding: 0.25rem 0.25rem;
right: -1px;
top: -1px;
font-size: smaller;
border-top-right-radius: 6px;
}
</style>
6 changes: 6 additions & 0 deletions peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ export default {
// number items from 1 consistently across pages
this.searchInfo.results[i].position = (this.page - 1) * this.pageSize + i + 1;
}
// determine best match: is the first result's score significantly better than the next?
if (this.page === 1 && this.searchInfo.results.length > 1 &&
this.searchInfo.results[0]._score / this.searchInfo.results[1]._score >= 1.2) {
this.searchInfo.results[0].best_match = true;
}
},
generateSearchParams () {
Expand Down

0 comments on commit b0f218e

Please sign in to comment.