user3578478
user3578478

Reputation: 81

Full Text Search MySQL

I Know how to use 'full text search MySQL'. What i want to know is how to search text for words . For exmaple :- We have three records in mysql as following

1.) This is a place for programmers .
2.) People visit places for travelling purposes.
3.) programmers visit this place site for coding purposes.

Now When A user searches for 'place for programmers'

Following should be the output

it should output rows that contain all words from the sentence in any order

1.)This is a place for programmers.
2.)programmers visit this place site for coding purposes.

Thank You For Helping .

Upvotes: 2

Views: 3184

Answers (2)

Shailesh Sonare
Shailesh Sonare

Reputation: 31

  1. Before using the full text search, index the columns

    ALTER TABLE <table> ADD FULLTEXT(column);
    
  2. Verify that it already in Full Text

    SELECT 
        index_name, group_concat(column_name) as columns
    FROM 
        information_Schema.STATISTICS 
    WHERE 
        table_schema = 'your_db_name' 
        AND table_name = 'table_name'
        AND index_type = 'FULLTEXT'
    GROUP BY 
        index_name;
    
  3. Then use following SQL

    SELECT * 
    FROM <table>
    WHERE MATCH(<column>) AGAINST('+place +for +programmers' IN BOOLEAN MODE)
    

Upvotes: 3

dannym87
dannym87

Reputation: 109

MySQL has MATCH..AGAINST for full text searches. Try the following,

SELECT * FROM <table> WHERE MATCH(<column>) AGAINST('+place +for +programmers' IN BOOLEAN MODE)

The +'s basically mean AND (you could use - for OR)

https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html

Upvotes: 1

Related Questions