Currently, I am doing a search function. In my database, I have this data:
- Keyword 1
- Keyword 2
- Keyword 3
- Key
- Key
And the user entered: "Key" as the keyword for search is my current query:
< Where to select from data> data (data_string like '$ key%' or data_string like '% $ key' like '% $ key') data / string like '% $ key') Actually, I have 2 questions Are:
How can I Sorted by equality From the above example, I wanted "Key" as my first result My current result is: Keyword 1, Keyword 2, Keyword 3, Keys and Keys
- < P> My SQL query only searches for "data_string" column, what if I want to clear the other columns? Do I need to do something like:
from where to select data (data_string '$ key%' or ' Like 'data_string' or '% $' like '% $ key%' or 'data_other' like '% $' or 'data_other' or data_other '% $ key%' or data_other '% $') - ...
Is there a better / faster question than Q2?
I'm not sure if likes
is the right way to do this. If you need to search within your text for keywords and sort by relevance score, then you should use it and forgive, if you are trying to do exactly, then it would be far away from But I recommend to see it. Some quotes from the MySQL Reference Manual:
1) How to create a full text index on more than one column of the table
mysql> Create table item (-> ID INT Unaccepted Atangement, Neil Primary Key, - & gt; Title VARCHAR (200), - & gt; Body Text, - & gt; FULLTEXT (Title, Body) - & gt;);
2) Sample data
mysql> Include in articles (title, body) value - & gt; ('MySQL Tutorial', 'Database for DBMS ...'), - & gt; ('How to Use MySQL Well', 'After You Gone Through One ...'), - & gt; ('Optimize MySQL', 'In this tutorial we will show ...'), - & gt; ('1001 MySQL Tricks', '1. Never run mysqld as root. 2. ...'), - & gt; ('MySQL vs Your SQL', 'In comparison to the following database ...'), - & gt; ('MySQL security', 'when properly configured, MySQL ...'); 3) Multiple columns for keywords and display results Sample question searched + Score:
mysql> SELECT id, body, against MATCH (title, body) - & gt; ('Security results to run as MySQL root') AS score - & gt; From the article where against the match (title, body) - & gt; ('Security result of running mysql as root') '; + ---- + ------------------------------------- + ------ ----------- + | ID | Body | Score | + ---- + ------------------------------------- + ------ ----------- + | 4 | 1. Never run mysqld as a root. 2. ... | 1.521 9271183014 | | 6 | When properly configured, MySQL ... | 1.3114095926285 | + ---- + ------------------------------------- + ------ ----------- +
Comments
Post a Comment