Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用搜索功能接口异常 #71

Closed
hhao97 opened this issue Nov 4, 2022 · 4 comments
Closed

使用搜索功能接口异常 #71

hhao97 opened this issue Nov 4, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@hhao97
Copy link

hhao97 commented Nov 4, 2022

镜像版本:answerdev/answer:latest

接口:/answer/api/v1/search?q=sdasd&order=relevance&page=1&size=20

返回值:
{"code":500,"reason":"base.unknown","msg":"Unknown error.","data":null}

日志:
2022-11-04 04:10:43.162 ERROR /go/src/github.com/answerdev/answer/internal/base/handler/handler.go:27 near "UNION": syntax error
/go/src/github.com/answerdev/answer/internal/controller/search_controller.go:41 github.com/answerdev/answer/internal/controller.(*SearchController).Search
/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 github.com/gin-gonic/gin.(*Context).Next
/go/src/github.com/answerdev/answer/internal/base/middleware/auth.go:47 github.com/answerdev/answer/internal/base/middleware.(*AuthUserMiddleware).Auth.func1

@LinkinStars
Copy link
Member

感谢问题反馈,已收到,正在修复中

@LinkinStars LinkinStars added the bug Something isn't working label Nov 4, 2022
@kumfo
Copy link
Member

kumfo commented Nov 4, 2022

请问一下能在config.yaml里的顶部加上一个debug: true,然后打一下日志,把日志结果里带有union 的sql语句贴一份吗?

我这边直接这样子没法复现。

@hhao97
Copy link
Author

hhao97 commented Nov 4, 2022

请问一下能在config.yaml里的顶部加上一个debug: true,然后打一下日志,把日志结果里带有union 的sql语句贴一份吗?

我这边直接这样子没法复现。

[xorm] [info]  2022/11/04 04:44:19.275497 [SQL] SELECT * FROM ((SELECT `question`.`id`,`question`.`id` as `question_id`,`title`,`original_text`,`question`.`created_at`,`user_id`,`vote_count`,`answer_count`,0 as `accepted`,`question`.`status` as `status`,`post_update_time`,((LENGTH(title) - LENGTH(REPLACE(title, ?, ''))) + (LENGTH(original_text) - LENGTH(REPLACE(original_text, ?, '')))) as relevance FROM `question` WHERE (`question`.`status`<? AND title LIKE ?) OR original_text LIKE ?) UNION ALL (SELECT `answer`.`id` as `id`,`question_id`,`question`.`title` as `title`,`answer`.`original_text` as `original_text`,`answer`.`created_at`,`answer`.`user_id` as `user_id`,`answer`.`vote_count` as `vote_count`,0 as `answer_count`,`adopted` as `accepted`,`answer`.`status` as `status`,`answer`.`created_at` as `post_update_time`,((LENGTH(`answer`.`original_text`) - LENGTH(REPLACE(`answer`.`original_text`, ?, '')))) as relevance FROM `answer` LEFT JOIN `question` ON `question`.id = `answer`.question_id WHERE `question`.`status`<? AND `answer`.`status`<? AND `answer`.original_text LIKE ?)) t ORDER BY relevance desc LIMIT 20 [sdasd sdasd 10 %sdasd% %sdasd% sdasd 10 10 %sdasd%] - 88.427µs

@kumfo
Copy link
Member

kumfo commented Nov 4, 2022

由于xorm底层的union组装导致的在sqlite下的查询会产生问题,已经处理掉了,在下个版本会进行修复,感谢

@fenbox fenbox closed this as completed Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants