Skip to content

Commit

Permalink
feat: 更新搜索逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Feb 18, 2023
1 parent 95d11ea commit b9bd8c6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2023-02-18T06:39:30.396Z"
"x-generation-date": "2023-02-18T15:17:00.843Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
11 changes: 5 additions & 6 deletions frontend/components/Navs/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const handleClickLink = () => {
const searchInput = useDebounceFn(async () => {
if (keyword.value !== '') {
const { data: SearchData_ } = await useFetch(
`/api/global/search?keyword=${keyword}`,
`/api/global/search?keyword=${keyword.value}`,
)
searchData.value = SearchData_.value
}
Expand Down Expand Up @@ -48,16 +48,15 @@ onUnmounted(() => {
type="search"
maxlength="32"
placeholder="搜索"
@input="searchInput"
>
<div class="search-icon" :class="{ 'search-active': isActive }">
<div class="search-icon" :class="{ 'search-active': isActive }" @click="searchInput">
<div class="i-carbon-search" />
</div>
<div v-if="!!searchData.hits" class="search-result" :class="{ hidden: !isActive }">
<div v-if="!!searchData" class="search-result" :class="{ hidden: !isActive }">
<div class="result-title">
共查到{{ searchData.estimatedTotalHits }}条结果
共查到{{ searchData?.hits.length || 0 }}条结果
</div>
<div class="result-list">
<div v-if="searchData?.hits" class="result-list">
<NuxtLink
v-for="item in searchData.hits"
:key="item.id"
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Types/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const changePageNum = async (direction) => {
.view-types {
transition: all .2s;
transform: translateZ(0);
@apply bg-jj-sidebar w-full fixed top-[5rem] lt-sm: (top-[4.333rem]) shadow-sm shadow-black/5 dark:shadow-white/5 h-[3.833rem] z-1;
@apply bg-jj-sidebar w-full fixed top-[5rem] lt-sm:(top-[4.333rem]) shadow-sm shadow-black/5 dark:shadow-white/5 h-[3.833rem] z-1;
}
.type-list-item {
Expand Down
3 changes: 3 additions & 0 deletions frontend/server/api/global/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ export default defineEventHandler(async (event): Promise<ISearch> => {
const { serverMeilisearchClient } = event.context
const query = getQuery(event)
const result = await serverMeilisearchClient.index('article').search(query?.keyword || '')
// 仅显示前十条
if (result.estimatedTotalHits > 10)
result.hits = result.hits.slice(0, 10)
return result
})

0 comments on commit b9bd8c6

Please sign in to comment.