Fix some bugs in full-text search

This commit is contained in:
2024-12-18 09:15:58 +08:00
parent 05df3fa376
commit 3f1e302d6b
2 changed files with 10 additions and 4 deletions

View File

@@ -372,9 +372,15 @@ func (ma *MApp) SearchHandler(ctx *gin.Context) {
nxtPage = allPage nxtPage = allPage
} }
// generate search posts
start := (curPage - 1) * size
offset := curPage * size
var resultPosts []model.MPost var resultPosts []model.MPost
for _, searchPost := range searchPosts { if len(searchPosts) > 0 {
resultPosts = append(resultPosts, *ma.IndexedPosts[searchPost.DocId]) for i := start; i < utils.Min(len(searchPosts), offset); i++ {
resultPosts = append(resultPosts, *ma.IndexedPosts[searchPosts[i].DocId])
}
} }
resData := gin.H{ resData := gin.H{

View File

@@ -86,7 +86,7 @@
<div class="col-12 col-md-8"> <div class="col-12 col-md-8">
<div class="search-post-pagination"> <div class="search-post-pagination">
<span class="search-post-pagination-item"> <span class="search-post-pagination-item">
<a href="/search?page={{ .page_info.pre_page }}"> <a href="/search?keyword={{ .search_post.keyword }}&page={{ .page_info.pre_page }}">
< <
</a> </a>
</span> </span>
@@ -94,7 +94,7 @@
{{ .page_info.cur_page }} &nbsp; / &nbsp; {{ .page_info.all_page }} {{ .page_info.cur_page }} &nbsp; / &nbsp; {{ .page_info.all_page }}
</span> </span>
<span class="search-post-pagination-item"> <span class="search-post-pagination-item">
<a href="/search?page={{ .page_info.nxt_page }}"> <a href="/search?keyword={{ .search_post.keyword }}&page={{ .page_info.nxt_page }}">
> >
</a> </a>
</span> </span>