问题描述
这段代码将执行搜索:
$ q = new Doctrine_RawSql();
$ q-> select('{p。*}')
- > from('cms_page p')
- > where('match .content)对(?)',$ user_query)
- > addComponent('p','CmsPage p');
这将执行。我希望结果按相关性排序
真正的sql必须看起来像:
从
cms_page中选择
p.id,
match(p.content)对(?)作为
作为p
订单
得分desc;
所以我需要得到那个匹配...反对条款在选择...我想。
我的crapshoot猜测在完成这个是:
$ q-对于('$ escaped_user_query')作为评分,选择({p.id},match({p.content})
- > from('cms_page p')
- > ; orderBy('score DESC')
- > addComponent('p','CmsPage p');
这不行。任何指针?
提前感谢
根据MySQL全文自然语言搜索文档:
这不适合您吗?
您可以阅读更多关于MySQL中的自然全文搜索
I'm trying to get fulltext searches to be sorted by relevance in aDoctrine_RawSql query.
This code will perform the search:
$q = new Doctrine_RawSql();
$q->select('{p.*}')
->from('cms_page p')
->where('match(p.content) against (?)', $user_query)
->addComponent('p', 'CmsPage p');
This will execute. I would like the results to be sorted by relevance
The real sql would have to look something like:
select
p.id,
match(p.content) against (?) as score
from
cms_page as p
order by
score desc;
So I need to get that match ... against clause in the select... I think.
My crapshoot guess at accomplishing this was:
$q->select("{p.id}, match({p.content}) against ('$escaped_user_query') as score")
->from('cms_page p')
->orderBy('score DESC')
->addComponent('p', 'CmsPage p');
That doesn't work. Any pointers?
Thanks in advance!
According to the MySQL fulltext natural language search docs:
Does this not work for you?
You can read more about natural fulltext search in MySQL here.
这篇关于如何使用Doctrine_RawSql进行全文搜索,并按相关性进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!