Skip to content

Commit

Permalink
feat: add the search.maxResults parameter to limit the returned searc…
Browse files Browse the repository at this point in the history
…h results
  • Loading branch information
razonyang committed Jan 20, 2023
1 parent 6f7fbe2 commit 7e925ce
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion assets/search/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class Engine {
if (lang) {
params.$and.push({ lang: '=' + lang });
}
resolve(this.fuse.search(params))
resolve(this.fuse.search(params, {
limit: parseInt(window.searchMaxResults),
}))
}, 1)
})
}
Expand Down
1 change: 1 addition & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ categoryId = "MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyODkzODg2"
# resultContentCharactersCount = 20 # The maximum characters count of result content for displaying.
indexPaginate = 100 # The number of pages per index file. Default to 1000.
# indexPreload = false # Do not preload index files.
# maxResults = 50
# Fuse.js options, the following options are available. See https://fusejs.io/api/options.html.
[search.fuse]
# ignoreLocation = true
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/layouts/search/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ title = "Search"
| `search` | Object | - | Search configuration.
| `search.paginate` | Integer | `10` | Pagination.
| `search.indexPaginate` | Integer | `1000` | Index file pagination.
| `search.maxResults` | Number | `100` | The max number of search results.
| `search.resultContentCharactersCount` | Integer | `240` | The maximum characters count of result content for displaying.
| `search.fuse` | Object | - | [Fuse.js options](https://fusejs.io/api/options.html).
| `search.fuse.ignoreLocation` | Boolean | `true` |
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/layouts/search/index.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ title = "Search"
| `search` | Object | - | 搜索配置。
| `search.paginate` | Integer | `10` | 分页。
| `search.indexPaginate` | Integer | `1000` | Index file pagination.
| `search.maxResults` | Number | `100` | 至多返回的搜索结果数目。
| `search.resultContentCharactersCount` | Integer | `240` | 搜索结果内容最大字符数。
| `search.fuse` | Object | - | [Fuse.js 参数](https://fusejs.io/api/options.html)
| `search.fuse.ignoreLocation` | Boolean | `true` |
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/docs/layouts/search/index.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ title = "Search"
| `search` | Object | - | 搜尋配置。
| `search.paginate` | Integer | `10` | 分頁。
| `search.indexPaginate` | Integer | `1000` | Index file pagination.
| `search.maxResults` | Number | `100` | 至多返回的搜索結果數目。
| `search.resultContentCharactersCount` | Integer | `240` | 搜尋結果內容最大字符數。
| `search.fuse` | Object | - | [Fuse.js 引數](https://fusejs.io/api/options.html)
| `search.fuse.ignoreLocation` | Boolean | `true` |
Expand Down
3 changes: 2 additions & 1 deletion layouts/partials/assets/search/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@
window.fuseOptions = JSON.parse('{{ $options | jsonify | safeHTML }}');
window.searchIndies = JSON.parse('{{ $searchIndies | jsonify }}');
window.searchMetaIndex = '{{ $meta.RelPermalink }}';
</script>
window.searchMaxResults = '{{ default 100 .Site.Params.search.maxResults }}';
</script>

0 comments on commit 7e925ce

Please sign in to comment.