mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
重构优化
This commit is contained in:
parent
3b66d6618d
commit
7f377038b4
@ -52,9 +52,9 @@ func (e *Engine) Search(searchKey string, pageSize int, currentDocId uint32, for
|
||||
kws := tokenizer.CutForSearch(searchKey) // TODO 检索用关键词处理
|
||||
|
||||
if searchKey == "" {
|
||||
log.Println("无条件查询")
|
||||
log.Println("无条件查询", "currentDocId=", currentDocId)
|
||||
} else {
|
||||
log.Println("查询", searchKey, ",分词后检索", kws)
|
||||
log.Println("查询", searchKey, ",分词后检索", kws, "currentDocId=", currentDocId)
|
||||
}
|
||||
|
||||
// 简单检查,存在无索引数据的关键词时,直接返回
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"glc/ldb/storage/indexdoc"
|
||||
"glc/ldb/storage/indexword"
|
||||
"glc/ldb/storage/logdata"
|
||||
"log"
|
||||
)
|
||||
|
||||
type SearchResult struct {
|
||||
@ -106,11 +107,12 @@ func SearchLogData(storeName string, pageSize int, currentDocId uint32, forward
|
||||
// 有关键词时走索引检索
|
||||
func SearchWordIndex(storeName string, word string, pageSize int, currentDocId uint32, forward bool) *SearchResult {
|
||||
|
||||
var rs = new(SearchResult) // 检索结果
|
||||
storeLogData := storage.NewLogDataStorageHandle(storeName) // 数据
|
||||
storeIndex := indexword.NewWordIndexStorage(storeName, word) // 索引
|
||||
totalCount := storeIndex.GetTotalCount(word) // 总件数
|
||||
rs.Total = cmn.Uint32ToString(storeLogData.TotalCount()) // 返回的总件数用10进制字符串形式以避免出现科学计数法
|
||||
var rs = new(SearchResult) // 检索结果
|
||||
logDataStorage := storage.NewLogDataStorageHandle(storeName) // 数据
|
||||
idxdocStorage := indexdoc.NewDocIndexStorage(storeName, word) // 关键词文档索引
|
||||
idxwordStorage := indexword.NewWordIndexStorage(storeName, word) // 关键词索引
|
||||
totalCount := idxwordStorage.GetTotalCount(word) // 总件数
|
||||
rs.Total = cmn.Uint32ToString(logDataStorage.TotalCount()) // 返回的总件数用10进制字符串形式以避免出现科学计数法
|
||||
|
||||
if totalCount == 0 {
|
||||
return rs
|
||||
@ -127,39 +129,42 @@ func SearchWordIndex(storeName string, word string, pageSize int, currentDocId u
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(storeIndex.GetDocId(word, i)).ToLogDataModel()) // 经索引取日志文档ID
|
||||
rs.Data = append(rs.Data, logDataStorage.GetLogDataDocument(idxwordStorage.GetDocId(word, i)).ToLogDataModel()) // 经索引取日志文档ID
|
||||
}
|
||||
} else if forward {
|
||||
// 后一页
|
||||
if currentDocId > 1 {
|
||||
var min, max uint32
|
||||
if currentDocId > totalCount {
|
||||
max = totalCount
|
||||
} else {
|
||||
max = currentDocId - 1
|
||||
max := idxdocStorage.GetWordDocSeq(word, currentDocId)
|
||||
if max == 0 {
|
||||
log.Println("无效的currentDocId(不应该)", currentDocId)
|
||||
return rs
|
||||
}
|
||||
max--
|
||||
var min uint32 = 1
|
||||
if max > uint32(pageSize) {
|
||||
min = max - uint32(pageSize) + 1
|
||||
} else {
|
||||
min = 1
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(storeIndex.GetDocId(word, i)).ToLogDataModel())
|
||||
rs.Data = append(rs.Data, logDataStorage.GetLogDataDocument(idxwordStorage.GetDocId(word, i)).ToLogDataModel())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 前一页
|
||||
if totalCount > currentDocId {
|
||||
var min, max uint32
|
||||
min = currentDocId + 1
|
||||
max = min + uint32(pageSize) - 1
|
||||
if currentDocId > 1 {
|
||||
min := idxdocStorage.GetWordDocSeq(word, currentDocId)
|
||||
if min == 0 {
|
||||
log.Println("无效的currentDocId(不应该)", currentDocId)
|
||||
return rs
|
||||
}
|
||||
min++
|
||||
max := min + uint32(pageSize)
|
||||
if max > totalCount {
|
||||
max = totalCount
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(storeIndex.GetDocId(word, i)).ToLogDataModel())
|
||||
rs.Data = append(rs.Data, logDataStorage.GetLogDataDocument(idxwordStorage.GetDocId(word, i)).ToLogDataModel())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user