使用全文在多个表中搜索

发布于 2024-08-15 17:34:36 字数 788 浏览 4 评论 0原文

我正在尝试使用 asp 和 SQL Server Full-text 进行详细搜索。

当提交关键字时,我需要在多个表中搜索。例如,

表 - 成员

  • member_id
  • contact_name

表 - 教育

  • member_id
  • school_name

我的查询;

从 Members mem FULL OUTER JOIN Education edu on edu.member_id=mem.member_id 中选择 mem.member_id、mem.contact_name、edu.member_id、edu.school_name,其中 CONTAINS (mem.contact_name, '""*"&keyword& ;"*""') 或 CONTAINS (edu.school_name, '""*"&keyword&"*""') order by mem.member_id desc;

此查询有效,但需要很长时间才能完成执行。

关键字是 Phill 的图像;如果 mem.contact_name 匹配,则列出它,或者如果 edu.school_name 匹配,则列出其教育程度与关键字匹配的人员。

我希望我能很好地解释:)抱歉我的英语。

I'm trying to make a detailed search with asp and SQL Server Full-text.

When a keyword submitted, I need to search in multiple tables. For example,

Table - Members

  • member_id
  • contact_name

Table - Education

  • member_id
  • school_name

My query;

select mem.member_id, mem.contact_name, edu.member_id, edu.school_name from Members mem FULL OUTER JOIN Education edu on edu.member_id=mem.member_id where CONTAINS (mem.contact_name, '""*"&keyword&"*""') or CONTAINS (edu.school_name, '""*"&keyword&"*""') order by mem.member_id desc;

This query works but it takes really long time to execute.

Image that the keyword is Phill; If mem.contact_name matches then list it, or if edu.school_name matches, list the ones whose education match the keyword.

I hope I could explain well :) Sorry for my english though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仅一夜美梦 2024-08-22 17:34:36

也许尝试包含合并数据集的索引视图 - 您可以在其中添加全文索引而不是单个表,并且它可以进一步扩展到您需要的任意数量的表。当然,唯一的技巧是空间......

Perhaps try an indexed view containing the merged dataset- you can add the fulltext index there instead of the individual tables, and it's further extensible to as many tables as you need down the line. Only trick, of course, is the space...

乖乖哒 2024-08-22 17:34:36

这就是我为多表全文搜索所做的事情。

不准确,但它会给出基本的想法。关键是给表虎钳包含 OR 条件。

DECLARE  @SearchTerm NVARCHAR(250)
    
SET @SearchTerm = '"Texas*"'

SELECT * FROM table1 
JOIN table2 on table1.Id = table2.FKID
WHERE (
        (@SearchTerm = '""') OR 
        CONTAINS((table1.column1, table1.column2, table1.column3), @SearchTerm) OR 
        CONTAINS((table2.column1, table2.column2), @SearchTerm)
      )

This is what I would do for my multi table full text search.

Not exact but it will give basic idea. the key thing is to give table vise contain with OR condition.

DECLARE  @SearchTerm NVARCHAR(250)
    
SET @SearchTerm = '"Texas*"'

SELECT * FROM table1 
JOIN table2 on table1.Id = table2.FKID
WHERE (
        (@SearchTerm = '""') OR 
        CONTAINS((table1.column1, table1.column2, table1.column3), @SearchTerm) OR 
        CONTAINS((table2.column1, table2.column2), @SearchTerm)
      )
知你几分 2024-08-22 17:34:36

我不明白有几点会影响你的速度。

  1. 您真的需要完整的外部连接吗?那会杀了你。看起来这些表是一对一的。在这种情况下,你不能将其设为内部联接吗?
  2. 你不能像这样将列列表传递给 contains 吗:

    SELECT mem.member_id,
         mem.contact_name,
         edu.member_id,
         edu.学校名称
    来自会员记忆
        内连接 education edu ON edu.member_id = mem.member_id
    WHERE 包含((mem.contact_name,edu.school_name),'*关键字*')
    按 mem.member_id DESC 排序 
    

有关 包含

Couple of points I don't understand that will be affecting your speed.

  1. Do you really need a full outer join? That's killing you. It looks like these tables are one to one. In that case can't you make it an inner join?
  2. Can't you pass a column list to contains like so:

    SELECT mem.member_id,
         mem.contact_name,
         edu.member_id,
         edu.school_name
    FROM members mem
        INNER JOIN education edu ON edu.member_id = mem.member_id
    WHERE Contains((mem.contact_name,edu.school_name),'*keyword*')
    ORDER BY mem.member_id DESC 
    

Further info about contains.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文