Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

Merge branch 'feat/1.1.1/ai' into test

aichy7bb7f84432d7
diff --cc go.mod
index 2e14d842,60ca3518..7de37070
--- a/go.mod
+++ b/go.mod
@@@ -36,14 -36,14 +36,23 @@@ require
github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20221018072427-a15dd1434e05
github.com/segmentfault/pacman/contrib/server/http v0.0.0-20221018072427-a15dd1434e05
github.com/spf13/cobra v1.6.1
++<<<<<<< HEAD
+ github.com/stretchr/testify v1.8.3
++=======
+ github.com/stretchr/testify v1.8.4
++>>>>>>> feat/1.1.1/ai
github.com/swaggo/files v1.0.0
github.com/swaggo/gin-swagger v1.5.3
- github.com/swaggo/swag v1.8.10
+ github.com/swaggo/swag v1.16.1
github.com/tidwall/gjson v1.14.4
github.com/yuin/goldmark v1.4.13
++<<<<<<< HEAD
+ golang.org/x/crypto v0.9.0
+ golang.org/x/net v0.10.0
++=======
+ golang.org/x/crypto v0.11.0
+ golang.org/x/net v0.12.0
++>>>>>>> feat/1.1.1/ai
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.14.2
@@@ -72,13 -70,12 +81,13 @@@ require
github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696 // indirect
github.com/dsoprea/go-png-image-structure v0.0.0-20190624104353-c9b28dcdc5c8 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
+ github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
- github.com/go-openapi/jsonpointer v0.19.5 // indirect
- github.com/go-openapi/jsonreference v0.20.0 // indirect
- github.com/go-openapi/spec v0.20.7 // indirect
- github.com/go-openapi/swag v0.22.3 // indirect
+ github.com/go-openapi/jsonpointer v0.20.0 // indirect
+ github.com/go-openapi/jsonreference v0.20.2 // indirect
+ github.com/go-openapi/spec v0.20.9 // indirect
+ github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/geo v0.0.0-20190812012225-f41920e961ce // indirect
@@@ -132,13 -127,12 +141,13 @@@
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
+ golang.org/x/arch v0.3.0 // indirect
golang.org/x/image v0.1.0 // indirect
- golang.org/x/mod v0.8.0 // indirect
- golang.org/x/sys v0.8.0 // indirect
- golang.org/x/text v0.9.0 // indirect
- golang.org/x/tools v0.6.0 // indirect
- google.golang.org/protobuf v1.30.0 // indirect
+ golang.org/x/mod v0.12.0 // indirect
+ golang.org/x/sys v0.10.0 // indirect
+ golang.org/x/text v0.11.0 // indirect
+ golang.org/x/tools v0.11.0 // indirect
+ google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
diff --cc go.sum
index 6f669520,073df70b..8ce1c0c6
--- a/go.sum
+++ b/go.sum
@@@ -205,32 -196,34 +205,37 @@@ github.com/go-logfmt/logfmt v0.3.0/go.m
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
- github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
+ github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
+ github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ=
+ github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA=
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
- github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
+ github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
+ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
- github.com/go-openapi/spec v0.20.7 h1:1Rlu/ZrOCCob0n+JKKJAWhNWMPW8bOZRg8FJaY+0SKI=
- github.com/go-openapi/spec v0.20.7/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
+ github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8=
+ github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
- github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
+ github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
+ github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
+ github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
-github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
+github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
+github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
-github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
+github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
+github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
-github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
-github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
+github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
+github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
diff --cc internal/controller/search_controller.go
index f0e18919,b9df6e7a..79e5d536
--- a/internal/controller/search_controller.go
+++ b/internal/controller/search_controller.go
@@@ -35,9 -48,27 +48,32 @@@ func (sc *SearchController) Search(ctx
return
}
dto.UserID = middleware.GetLoginUserIDFromContext(ctx)
+ unit := ctx.ClientIP()
+ if dto.UserID != "" {
+ unit = dto.UserID
+ }
+ isAdmin := middleware.GetUserIsAdminModerator(ctx)
+ if !isAdmin {
+ captchaPass := sc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionSearch, unit, dto.CaptchaID, dto.CaptchaCode)
+ if !captchaPass {
+ errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
+ ErrorField: "captcha_code",
+ ErrorMsg: translator.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
+ })
+ handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
+ return
+ }
+ }
++<<<<<<< HEAD
+ resp, total, err := sc.searchService.Search(ctx, &dto)
+
++=======
+ resp, total, extra, err := sc.searchService.Search(ctx, &dto)
+ if !isAdmin {
+ sc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionSearch, unit)
+ }
++>>>>>>> feat/1.1.1/ai
handler.HandleResponse(ctx, err, schema.SearchListResp{
Total: total,
SearchResp: resp,
diff --cc internal/schema/search_schema.go
index 95b578c2,7f3d1867..3c1b187c
--- a/internal/schema/search_schema.go
+++ b/internal/schema/search_schema.go
@@@ -1,83 -1,15 +1,85 @@@
package schema
+import (
+ "github.com/answerdev/answer/internal/base/constant"
+ "github.com/answerdev/answer/plugin"
+)
+
type SearchDTO struct {
- UserID string // UserID current login user ID
- Query string `validate:"required,gte=1,lte=60" json:"q" form:"q"` // Query the query string
- Page int `validate:"omitempty,min=1" form:"page,default=1" json:"page"` //Query number of pages
- Size int `validate:"omitempty,min=1,max=50" form:"size,default=30" json:"size"` //Search page size
- Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" json:"order" enums:"newest,active,score,relevance"`
+ UserID string // UserID current login user ID
+ Query string `validate:"required,gte=1,lte=60" json:"q" form:"q"` // Query the query string
+ Page int `validate:"omitempty,min=1" form:"page,default=1" json:"page"` //Query number of pages
+ Size int `validate:"omitempty,min=1,max=50" form:"size,default=30" json:"size"` //Search page size
+ Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" json:"order" enums:"newest,active,score,relevance"`
+ CaptchaID string `json:"captcha_id"` // captcha_id
+ CaptchaCode string `json:"captcha_code"`
}
+type SearchCondition struct {
+ // search target type: all/question/answer
+ TargetType string
+ // search query user id
+ UserID string
+ // vote amount
+ VoteAmount int
+ // only show not accepted answer's question
+ NotAccepted bool
+ // view amount
+ Views int
+ // answer count
+ AnswerAmount int
+ // only show accepted answer
+ Accepted bool
+ // only show this question's answer
+ QuestionID string
+ // search query tags
+ Tags []string
+ // search query keywords
+ Words []string
+}
+
+// SearchAll check if search all
+func (s *SearchCondition) SearchAll() bool {
+ return len(s.TargetType) == 0
+}
+
+// SearchQuestion check if search only need question
+func (s *SearchCondition) SearchQuestion() bool {
+ return s.TargetType == constant.QuestionObjectType
+}
+
+// SearchAnswer check if search only need answer
+func (s *SearchCondition) SearchAnswer() bool {
+ return s.TargetType == constant.AnswerObjectType
+}
+
+// Convert2PluginSearchCond convert to plugin search condition
+func (s *SearchCondition) Convert2PluginSearchCond(page, pageSize int, order string) *plugin.SearchBasicCond {
+ basic := &plugin.SearchBasicCond{
+ Page: page,
+ PageSize: pageSize,
+ Words: s.Words,
+ TagIDs: s.Tags,
+ UserID: s.UserID,
+ Order: order,
+ QuestionID: s.QuestionID,
+ VoteAmount: s.VoteAmount,
+ ViewAmount: s.Views,
+ AnswerAmount: s.AnswerAmount,
+ }
+ if s.Accepted {
+ basic.AnswerAccepted = plugin.AcceptedCondTrue
+ } else {
+ basic.AnswerAccepted = plugin.AcceptedCondAll
+ }
+ if s.NotAccepted {
+ basic.QuestionAccepted = plugin.AcceptedCondFalse
+ } else {
+ basic.QuestionAccepted = plugin.AcceptedCondAll
+ }
+ return basic
+}
+
type SearchObject struct {
ID string `json:"id"`
QuestionID string `json:"question_id"`