- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以想到在 mysql 中执行此操作的复杂且丑陋的方法,但我正在寻找一种不错的方法。假设我有一堆学校名称,比如
Meopham County Infant School
Speldhurst Nursery School
Rainbow Pre-School
The Annex School House
Fleet Learning Zone
Dartford Grammar School
Kiddliwinks
Hextable Kindergarten
The Rocking Horse Montessori Kinder
Little Angels Day Nursery
我有一个停用词列表:
["school", "primary", "nursery", "college", "junior", "church", "cofe", "community", "infant"]
我有一个 ruby 函数“short_name”,它返回学校名称,但不包括,任何停用词的第一个实例,这样我们就可以得到
"Bower Grove School" => "Bower Grove"
"Fulston Manor School" => "Fulston Manor"
"St Johns Church Hall Play" => "St Johns"
"St Botolph's Church of England Voluntary Aided Primary School" => "St Botolph's"
"Fawkham House School" => "Fawkham House"
"Silverdale Day Nursery" => "Silverdale Day"
"Vigo Village School" => "Vigo Village"
"Sevenoaks Primary School" => "Sevenoaks"
"High Weald Academy" => "High Weald Academy"
"The Ebbsfleet Academy" => "The Ebbsfleet Academy"
没关系。我的问题是:在 mysql 中进行上述字符串处理的最简单方法是什么?
例如,如果我想通过这个短名称进行搜索,我想做类似的事情
"select * from schools where <function(name)> = 'Bower Grove'"
最简单的方法是什么<function>
?我认为使用正则表达式的 substring() 和 locate() 的某种组合是可行的方法,但看起来我不能将正则表达式与定位一起使用。
我猜正则表达式是
"school|primary|nursery|college|junior|church|cofe|community|infant"
谢谢,麦克斯
最佳答案
MySQL 确实支持正则表达式。不幸的是,它仅用于匹配。
这是一种方法:
select least(substring_index(schoolname, ' School', 1),
substring_index(schoolname, ' Primary', 1),
. . .
)
这使用 substring_index()
来提取分隔符之前的字符串的第一部分。如果分隔符不存在,您将获得整个字符串。 least()
函数将选择最短的字符串。
这假定该关键字前面有一个空格。毕竟,您可能不想为了“小天使学校”这样的名称而完全消除所有内容。
关于mysql:最好的说法是 "the string up to the first instance of any of the following keywords"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28673916/
我正在尝试创建一个类似 Twitter 的关注/关注系统。表格设计是这样的 - leader_id | following_id | is_mutual 1 |
尊敬的数据库专家/程序员: 我有一个mysql表,里面有用户信息,比如 id user_id name etc. 1 userA 2
我正在尝试设置我的 User GraphQL 模型以具有要查询的 followers 和 following 属性。但是,我无法在 Sequelize 中建立关系。我正在尝试使用 Follower 模
在我的网站上,我有一个类似 twitter 的概念,我有一个具有以下结构的用户连接表, ============================================= ==========
下面列出的区别是什么: 最佳答案 首先,你知道Meta Robots Tags吗?Meta Robots Tags 是告诉蜘蛛或爬虫要抓取或索引哪些页面。 跟随意味着:页面将被抓取。 No
我正在做一些项目,我在考虑关注者和像推特这样的关注系统。我在数据库中有成员表。我怎样才能做关注者系统。逻辑是什么?我做了类似的事情:我创建了名称跟随的新表,我有 3 行。这些行是 id、user_id
这是用于 C 代码检测。我正在尝试标记没有中断的 case 语句。当 break 语句之前有多行时,树的层次结构如下所示。这是 C 中的示例: switch (x) { case 1: i
大家好,我正在使用 MySQL 和 PHP 制作关注者/被关注系统,所以我想获取我关注的用户的所有视频并按 ID 描述排序。 数据库架构: 例如,如果我的 user_id = 1,并且如果我正在关注
我正在尝试根据#following #followers 找到一个计算推特用户“重要性”的方程式 我要考虑的事情: 1. #followers/#following越多,他越重要。 2. 在 20/2
这是我得到的错误 undefined method `followed_users?' for # 提取的源代码(大约第 3 行): 1: 2: 3: 4: 5: 6:
我有一个用户模型,可以创建关系以拥有关注者并关注其他人,我从 Rails 教程中学到的一切都非常有效。一件事是,我正在尝试通过添加能够看到其他人的关注者并能够拥有关注/关注按钮选项的选项来将其推进到下
我正在尝试通过 Twitter Javascript Api(请参阅 here )检查登录用户是否在 Twitter 上关注我。如果没有,我将显示一个关注按钮。现在我似乎无法找出命令 isFollow
我希望能够使用 iOS 5 的 Twitter API 将所有用户关注者和关注者用户名放入 NSDictionary... 不过我遇到了障碍。我不知道如何使用 Twitter API 来执行此操作..
希望在域之后但在其他任何内容之前获取值。 因此 URL 的示例是: www.domain.com/following#2 我只想从该 url 中获取后面的单词。 目前有这个可以重定向用户并在任何片段等
我有下表: 关系 id、follower_id、followee_id、状态 用户 id、姓名、电子邮件 我想查找正在关注或被特定用户关注的所有用户。 这是我到目前为止所拥有的,但速度非常慢: SEL
我是 state Management 的新手,正在使用 provider package 。产生这些类型的异常有多少种不同的原因,我该如何解决,此异常是在 didChangeDependencies
所以我在这里尝试制作一个类似 Instagram 的应用程序,但仅适用于汽车,我尝试单击“关注”和“关注者”来查看我关注的人和关注我的人,但我不确定为什么会有NPE吗... 我成功地可以关注用户,用户
我是 state Management 的新手,正在使用 provider package 。产生这些类型的异常有多少种不同的原因,我该如何解决,此异常是在 didChangeDependencies
我讨厌发布“这应该很容易,我错过了什么”问题,但是......这应该很容易,我错过了什么?我在这个测试代码上没有得到匹配,我不明白为什么。模式是(或应该是)“任何三个数字,后跟任何三个相同的数字,后跟
我正在研究 Chapter 11在 Hartl 的教程中,试图让用户 Controller 中的未登录用户访问关注者和关注页面通过。我遇到了一个错误,Rails 会提示未定义的 admin? 方法,尽
我是一名优秀的程序员,十分优秀!