P
P
pratamishus2011-04-24 11:58:30
MySQL
pratamishus, 2011-04-24 11:58:30

MySQL search via match() against()?

Hello!
I have a search that searches using match() against(). But the problem is that it does not give accurate results. For example, if you do a search for “cat”, it displays not cats on the front page, but what contains “Category”.
The question is simple - How do I make LIKE '% cat %' OR tags LIKE '% cat' OR tags LIKE 'cat %' in match() against()
More details:
Tags are stored as "animal cat happy" or "" "inventory categories"
Here is the sql to search compact disc

SELECT *, MATCH (tags) AGAINST('&gt;&gt;&quot;compact disc&quot; &gt;(+compact* +disc* ) &lt;(compact* disc* )' IN BOOLEAN MODE) as rel FROM icons <br/>
WHERE MATCH (tags) AGAINST('&gt;&gt;&quot;compact disc&quot; &gt;(+compact* +disc* ) &lt;(compact* disc* )' IN BOOLEAN MODE) <br/>
ORDER BY rel DESC

if you make a request through LIKE, you have to do a UNION to distribute the data by relevance (in the case of the word "cat")
(SELECT * FROM icons WHERE tags LIKE '% cat %' OR tags LIKE '% cat' OR tags LIKE 'cat %')<br/>
UNION<br/>
(SELECT * FROM icons WHERE tags LIKE '%cat%')<br/>

In this case, the result is better, but the load on the server is greater if the search is for 2 or more words.
I tried to pull the tags into a separate table and create a many-to-many relationship, but this also loads the server more than the match against option.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
XaosSintez, 2011-04-24
@XaosSintez

Use Sphinx. Full-text search in MySQL - the same as

M
Melanitsky, 2011-04-24
@Melanitsky

LIKE gives a huge load on the DBMS.
It all depends on which table engine you are using. For full-text search with morphology, sphinx is the best choice.
If to do through match it is best of all MyISAM. but in general www.mysql.ru/docs/man/Fulltext_Search.html
SELECT word FROM table WHERE
MATCH (word) AGAINST ('cat*' IN BOOLEAN MODE)

S
Sergey Beresnev, 2011-04-25
@sectus

If the string with tags in the database starts with a space and ends with a space, then three conditions will not be necessary: ​​)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question