2009-08-31 29 views
1

我有三個信息表business_id是公共線程。我有兩個輸入字段,一個用於常規搜索(用戶可以搜索他們想要的任何內容)和一個zip輸入。在PHP方面,我找到了一般搜索字符串,並將其設置爲$search,並將zip設置爲$zip多表全文搜索對兩個PHP變量

我如何使用$search變量MATCH任何全文indecies 然後限制使用從表C $zip然後僅返回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 

任何幫助,將不勝感激!

回答

0

您可以使用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' 
+0

我想補充c.name ,b.category,b.subcat也是如此。 – 2009-08-31 02:40:40

+0

全文搜索僅適用於各自的索引。就我所知,你不能做一個多表全文索引。 – Eric 2009-08-31 02:42:58