gpt4 book ai didi

php - 改进用于搜索的 SQL 查询

转载 作者:行者123 更新时间:2023-11-29 03:23:39 24 4
gpt4 key购买 nike

有人可以帮助改进我的 SQL 查询吗?它用于站点搜索。以下是查询:

SELECT j_author.author_id as authorID, author_name, author_description, author_cat, author_city, author_state, points, (SELECT SUM(rate_value) FROM j_rating WHERE j_rating.author_id = authorID ) AS rating_value
FROM j_author
JOIN j_author_category ON j_author.author_cat = j_author_category.author_cat_id
WHERE author_name LIKE '%" . $keyword . "%'
OR author_city LIKE '%" . $keyword . "%'
ORDER BY rating_value DESC

它有效,但不是我想要的。例如,如果我搜索“edu”并且有一个名为 educate 的作者或城市,它会返回作者或城市。但如果搜索“受过教育的人”,则不会返回任何结果。

我也尝试过使用:

SELECT j_author.author_id as authorID, author_name, author_description, author_cat, author_city, author_state, points, (SELECT SUM(rate_value) FROM j_rating WHERE j_rating.author_id = authorID ) AS rating_value,             
MATCH(j_author.author_name, j_author.author_city) AGAINST ('$keyword' IN BOOLEAN MODE) AS score
FROM j_author
JOIN j_author_category ON j_author.author_cat = j_author_category.author_cat_id
WHERE MATCH(j_author.author_name, j_author.author_city) AGAINST ('$keyword' IN BOOLEAN MODE)
ORDER BY `score` DESC

但每次我使用这种方法时,当我搜索“edu”时,它不会返回任何结果。

我想要的是,如果“受过教育的人”是输入的搜索关键字,它应该使用“受过教育”和“人”作为单独的关键字进行搜索,并返回与任何关键字匹配的结果。此外,当“edu”是关键字时,它应该返回所有名称或城市中包含 edu 的作者

最佳答案

如果您无法在将值传递到查询之前拆分文本,那么您可能正在寻找这样的内容:

Transact-SQL: How do I tokenize a string?

如果您将查询拆分为预先确定的字符并针对每个“标记”执行查询,您应该能够实现您的目标。

关于php - 改进用于搜索的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39879287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com