检索结果后处理

This commit is contained in:
gotoeasy 2023-08-23 09:51:07 +08:00
parent 286be910e1
commit cf32fe9ce5
3 changed files with 18 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package ldb
import (
"glc/com"
"glc/conf"
"glc/ldb/search"
"glc/ldb/storage"
"glc/ldb/storage/indexword"
@ -75,24 +74,13 @@ func (e *Engine) Search(searchKey string, system string, minDatetime string, max
}
}
var rs *search.SearchResult
if len(kws) == 0 {
// 无条件浏览模式
rs = search.SearchLogData(e.storeName, currentDocId, forward, minDatetime, maxDatetime)
} else {
// 多关键词查询模式
rs = search.SearchWordIndex(e.storeName, kws, currentDocId, forward, minDatetime, maxDatetime)
return search.SearchLogData(e.storeName, currentDocId, forward, minDatetime, maxDatetime)
}
if !forward {
// 修复最多匹配件数检索非检索更多数据量少于1页时最多匹配件数=检索结果件数,避免个别特殊场景下两者不一致
size := len(rs.Data)
if size < conf.GetPageSize() {
rs.Count = cmn.IntToString(size)
}
}
return rs
// 多关键词查询模式
return search.SearchWordIndex(e.storeName, kws, currentDocId, forward, minDatetime, maxDatetime)
}
// 添加日志

View File

@ -18,9 +18,10 @@ import (
)
type SearchResult struct {
Total string `json:"total,omitempty"` // 日志总量件数用10进制字符串形式以避免出现科学计数法
Count string `json:"count,omitempty"` // 当前条件最多匹配件数用10进制字符串形式以避免出现科学计数法
Data []*logdata.LogDataModel `json:"data,omitempty"` // 检索结果数据(日志文档数组)
Total string `json:"total,omitempty"` // 日志总量件数用10进制字符串形式以避免出现科学计数法
Count string `json:"count,omitempty"` // 当前条件最多匹配件数用10进制字符串形式以避免出现科学计数法
PageSize string `json:"pagesize,omitempty"` // 每次检索件数
Data []*logdata.LogDataModel `json:"data,omitempty"` // 检索结果数据(日志文档数组)
}
type WidxStorage struct {

View File

@ -33,5 +33,16 @@ func LogSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
eng := ldb.NewEngine(storeName)
rs := eng.Search(searchKey, system, datetimeFrom, datetimeTo, loglevel, currentId, forward)
// 检索结果后处理
rs.PageSize = cmn.IntToString(conf.GetPageSize())
if !forward {
// 修复最多匹配件数检索非检索更多数据量少于1页时最多匹配件数=检索结果件数,避免个别特殊场景下两者不一致
size := len(rs.Data)
if size < conf.GetPageSize() {
rs.Count = cmn.IntToString(size)
}
}
return gweb.Result(rs)
}