是否有人知道如何加快此查询。
我正在寻找关键词“bar”和“cafe”在1个桌子上的几个领域,如下图所示,然后我想通过他们最合适的命中来订购它所以我做所有的领域和案例时 - 可能性,当然这会减慢它的速度,我该怎样做才能加快速度呢?
首先我按照FIELD的确切命令进行订购,在这种情况下没有意义,因为关键字是酒吧和咖啡馆但是当我查找“公司名称”时,我希望这家公司成为#1
然后我尝试按类似的名称/名称部分进行排序,如果确切的一个没有到达正确的字段。
之后,我按“金额”订购,可以是8,30欧元到500欧元,之后会有0欧元即将开始加载
然后我再次使用所有免费条目我尝试通过“几个通配符”的情况下订购它们
问题实际上是顺序,查询本身只需要大约0.02秒而没有任何顺序,而顺序则大约需要5-7秒。 我可能错了,我可以在查询中加快速度......?
这些字段当然有索引。
任何帮助都将受到高度赞赏:)
select * FROM companytable where
companytable.aktiv='1'
and platform='1'
and (lcase(companytable.company_name) like '%bar%'
or lcase(companytable.company_name_modrewrite) like '%bar%'
or lcase(companytable.company_www) like '%bar%'
or lcase(companytable.company_nachname) like '%bar%'
or lcase(companytable.company_home_text) like '%bar%'
or lcase(companytable.keywords) like '%bar%'
or lcase(companytable.company_name) like '%cafe%'
or lcase(companytable.company_name_modrewrite) like '%cafe%'
or lcase(companytable.company_www) like '%cafe%'
or lcase(companytable.company_nachname) like '%cafe%'
or lcase(companytable.company_home_text) like '%cafe%'
or lcase(companytable.keywords) like '%cafe%'
or lcase(companytable.company_name) like '%bar cafe%'
or lcase(companytable.company_name_modrewrite) like '%bar_cafe%'
or lcase(companytable.company_www) like '%bar cafe%'
or lcase(companytable.company_nachname) like '%bar cafe%'
or lcase(companytable.company_home_text) like '%bar cafe%'
or lcase(companytable.keywords) like '%bar cafe%')
order by
FIELD(lcase(companytable.company_name),'bar cafe') desc,
FIELD(lcase(companytable.company_name),'cafe bar') desc,
case when lcase(companytable.company_name) LIKE "%cafe bar%" then 1 END desc,
case when lcase(companytable.company_name) LIKE "%bar cafe%" then 1 END desc,
cast(companytable.amount as unsigned) desc,
case when lcase(companytable.company_name) LIKE "bar cafe%" then 1 END desc,
case when lcase(companytable.company_name) LIKE "%bar cafe%" then 1 END desc,
case when lcase(companytable.company_name) LIKE "%bar cafe" then 1 END desc,
case when lcase(companytable.company_name) LIKE "cafe bar%" then 1 END desc,
case when lcase(companytable.company_name) LIKE "%cafe bar%" then 1 END desc,
case when lcase(companytable.company_name) LIKE "%cafe bar" then 1 END desc,
FIELD(lcase(companytable.company_name),'bar cafe') desc,
companytable.company_name