1

I somewhere read earlier about this, and failed to find it this time.

I have a table with 4 columns as follows:

+----+------+-------+-------------+
| id | Name | Title | Description |
+----+------+-------+-------------+

Now I read that we can combine the Name, Title and Description in such a way that you can search later on and output will be sorted based on the text repeat.

For eg: If I search for "Who is James"

It will search for it in Name, Title and Description and will return the rows based on Existence of this string Partially or fully within the columns.

Please help!!!

3 Answers 3

2

A better approach is to use the full text search feature from MySQL, a little example in your case would be:

//Alter the table to add full text index
ALTER TABLE user ADD FULLTEXT keyword (name, title, description)

//Perform the query like this
SELECT * FROM user MATCH (name, title, description) AGAINST 
('Who is james'  IN NATURAL LANGUAGE MODE)

For further reference please refer to the documentation:

https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Sign up to request clarification or add additional context in comments.

Comments

1

You can take advantage of MySQL MyISAM Full TEXT Searching methodology. Add the columns you want to add support full text searching like

ALTER TABLE mytable ADD FULLTEXT(Name,Title,Description);

now search any query on these columns order by best matched strings like:

        SELECT *,
            MATCH(Name,Title,Description) AGAINST('$keyword') AS score
        FROM mytable
        WHERE MATCH(Name,Title,Description) AGAINST('$keyword')
        ORDER BY score DESC

Comments

0

If I understood the question correctly, the most obvious (and probably slowest) method would be to use LIKE, for example:

SELECT * FROM mytable WHERE Name LIKE '%James%' OR Title LIKE '%James%' OR Description LIKE '%James%'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.