SQL 基本全文搜索
我没有太多使用 TSQL 或 SQL Server 的全文搜索功能,所以请耐心等待。
我有一个像这样的表 nvarchar 列 (Col):
Col ... more columns
Row 1: '1'
Row 2: '1|2'
Row 3: '2|40'
我想要进行搜索以匹配类似的用户。因此,如果我有一个 Col 值为“1”的用户,我希望搜索返回前两行。如果我有一个 Col 值为“1|2”的用户,我希望首先返回第 2 行,然后返回第 1 行。如果我尝试匹配 Col 值为“4”的用户,我不会得到任何结果。我想过通过拆分我用来查询的值来执行“包含”,但它不起作用,因为“2|40”包含 4...
我查找了有关使用“FREETEXT”关键字的文档,但我不这样 做不认为这对我有用,因为我本质上需要使用“|”将 Col 值分解为单词作为休息。
谢谢, 约翰
I have not worked much with TSQL or the full-text search feature of SQL Server so bear with me.
I have a table nvarchar column (Col) like this:
Col ... more columns
Row 1: '1'
Row 2: '1|2'
Row 3: '2|40'
I want to do a search to match similar users. So if I have a user that has a Col value of '1' I would expect the search to return the first two rows. If I had a user with a Col value of '1|2' I would expect to get Row 2 returned first and then Row 1. If I try to match users with a Col value of '4' I wouldn't get any results. I thought of doing a 'contains' by splitting the value I am using to query but it wouldn't work since '2|40' contains 4...
I looked up the documentation on using the 'FREETEXT' keyword but I don't think that would work for me since I essentially need to break up the Col values into words using the '|' as a break.
Thanks,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应将“1|2”之类的值存储在字段中来存储 2 个值。如果最多有 2 个值,则应使用 2 个字段来存储它们。如果您可以有 0 多个值,则应该将它们存储在一个新表中,并使用指向表主键的外键。
如果您的表中最多只有 2 个值。您可以这样找到您的数据:
Parsename 最多可以处理 4 个值。如果 'col' 可以包含超过 4 个值,请使用此值
You should not store values like '1|2' in a field to store 2 values. If you have a maximum of 2 values, you should use 2 fields to store them. If you can have 0-many values, you should store them in a new table with a foreign key pointing to the primary key of your table..
If you only have max 2 values in your table. You can find your data like this:
Parsename can handle max 4 values. If 'col' can contain more than 4 values use this
需要将其与案例混合,以备不时之需 |但这会返回左侧和右侧
Need to mix this in with a case for when there is no | but this returns the left and right hand sides