开发者

mysql search top match should come first

in the match - against am getting the correct results, there is no problem but the thing i want is the result combination.

Like for "computer graphics" i am getting results for "+computer +graphics" as "computer" alone results and "computer graphics" res开发者_C百科ults and "graphics" results and etc.

Here i want "computer graphics" results first then the other single word match results. How can i bring those first. Help me some one please


you should order by relevance: search for the same query you use in WHERE, call is RELEVANCE and then order by that field.

SELECT MATCH('...') AGAINST ('...') as Relevance FROM table WHERE MATCH('...') AGAINST('...' IN BOOLEAN MODE) ORDER BY Relevance DESC


This can't be done in MySQL fulltext search without a bit of hoop jumping.

You basically need to run the search twice to get your desired results. First, run a boolean fulltext search using double quotes to enclose the exact phrase being searched for. The double quotes in boolean mode will return exact matches only. Once you have those results, then your normal natural-language search. It's the normal, natural language search that is giving you trouble with partial matches. You'll need to manually combine the two search results.

While MySQL fulltext is decent for simple searching needs, it's not a great search solution. Consider something with more power, like Sphinx, Solr / Lucene, or even something like ElasticSearch.


Assuming we're talking about a full-text index:

... ORDER BY MATCH('computer graphics') AGAINST (some,columns) DESC;


Entries in table

what is computer? what is graphics on computer? what is computer graphics? what is graphics?

QUERY : select *,MATCH(field1,field2) AGAINST ("+computer +graphics" IN BOOLEAN MODE) as results from $table where MATCH(field1,field2) AGAINST ("+computer +graphics" IN BOOLEAN MODE) ORDER BY results ASC

IT RETURNS exact results some where in the middle and others are first.

Like what is computer graphics? what is graphics on computer? what is computer? what is graphics?

How it can be corrected....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜