fix(search): Fixed #307, Closes #307. when connection mysql(MariaDB) with option of 'parseTime=true', the time of search result is parse error.

This commit is contained in:
kumfo 2023-09-14 10:04:09 +08:00
parent c55cecc6ad
commit 8a2522cb3b
1 changed files with 8 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
tagcommon "github.com/answerdev/answer/internal/service/tag_common" tagcommon "github.com/answerdev/answer/internal/service/tag_common"
"github.com/answerdev/answer/plugin" "github.com/answerdev/answer/plugin"
"github.com/segmentfault/pacman/log"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -469,7 +470,13 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)
for _, r := range res { for _, r := range res {
questionIDs = append(questionIDs, string(r["question_id"])) questionIDs = append(questionIDs, string(r["question_id"]))
userIDs = append(userIDs, string(r["user_id"])) userIDs = append(userIDs, string(r["user_id"]))
tp, _ := time.ParseInLocation("2006-01-02 15:04:05", string(r["created_at"]), time.Local) tp, pe := time.ParseInLocation("2006-01-02 15:04:05", string(r["created_at"]), time.Local)
if pe != nil {
tp, pe = time.ParseInLocation("2006-01-02T15:04:05Z", string(r["created_at"]), time.Local)
if pe != nil {
log.Error("parse time error: ", pe)
}
}
object := &schema.SearchObject{ object := &schema.SearchObject{
ID: string(r["id"]), ID: string(r["id"]),
QuestionID: string(r["question_id"]), QuestionID: string(r["question_id"]),