【问题标题】:Multiple table Fulltext search against two php variables针对两个 php 变量的多表全文搜索
【发布时间】:2009-08-31 10:40:48
【问题描述】:

我有三个信息表,其中 business_id 是公共线程。我有两个输入字段,一个用于一般搜索(用户可以搜索他们想要的任何内容)和一个 zip 输入。在 php 方面,我捕获了一般搜索字符串并将其设置为 $search 并将 zip 设置为 $zip

如何使用$search 变量来MATCH 任何全文索引然后 使用$zip 限制这些匹配项那么只返回表c中的id?

我的数据库结构如下:

table coup
    id  << this is the my desired information from the search
    timestamp
    business_id
    coupvalue
    startdate
    enddate
    username
    status
    terms
    image
    description
        primary = id
        fulltext = name
table bloc
    id
    address
    city
    state
    zip
    business_id
    phone
    lat
    lon
        primary = id
table bus
    business_id
    name
    timestamp
    category
    subcat
        primary = business_id
        fulltext = name,category,subcat

任何帮助将不胜感激!

【问题讨论】:

    标签: php mysql html


    【解决方案1】:

    您可以在匹配项中使用or 条件:

    select
        c.id
    from
        coup c
        inner join bus b on
            c.business_id = b.business_id
        inner join block z on
            c.buisness_id = z.business_id
        where
            (match(c.name) against ('$search')
            or match (b.name, b.category, b.subcat) against ('$search'))
            and z.zip = '$zip'
    

    我尚未对其进行基准测试,但这可能会更快:

    select
       c.id
    from
        (select id, business_id 
         from coup 
         where match(name) against ('$search')
        ) as c
        left join
           (select business_id 
            from bus 
            where match(name, category, subcat) against ('$search')
           ) as b on
            c.business_id = b.business_id 
        inner join bloc z on
            c.business_id = z.business_id
    where
        z.zip = '$zip'
    

    【讨论】:

    • 我也想将 c.name,b.category,b.subcat 添加到比赛中。
    • 全文搜索仅适用于它们各自的索引。据我所知,你不能做一个多表全文索引。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2010-12-28
    • 2010-11-10
    • 1970-01-01
    相关资源
    最近更新 更多