MySQL Fulltext searching and minimum search term length - mysql

I am using fulltext searching in mysql to search a database of videos I have, however when I search my videos some results will never get returned because the title I am searching for is less than the ft_min_word_len set in MySQL's settings.
mysql_query("SELECT MATCH(videoDescription) AGAINST('".$searchString."' IN NATURAL LANGUAGE MODE)
FROM videos
LIMIT ".$start.",".$end."");
I tried firing up the mysql console to change the setting, however it told me it is read only. The only possible solution I have seen is to have the setting overridden at startup with option files. How do I use option files to overwrite the ft_min_word_len to 2 at startup?

ft_min_word_len is a system variable, that has to be set at the startup of the MySQL server.
This can be done passing parameters on the command-line used to start MySQL, or (recommended, I'd say), using a file containing options -- generally, for example, something like /etc/my.cnf or /etc/mysql/my.cnf should do the trick.
For more informations about setting system variables, you can take a look at the following section of the manual :
4.2.3. Specifying Program Options
Also, don't forget that you'll have to rebuild your fulltext index, after changing that parameter, so the new value is taken into account.

Related

Setting ft_stopword_file back to default (built-in) without restarting MySQL

I need to test something by changing the ft_stopword_file without restarting the server. I know that SET GLOBAL works to change global variables until the next restart. After testing, I want to return it to its default value just in case it breaks something.
The problem is: if I understood correctly, ft_stopword_file only resets back to its default value (its built-in word set) when being completely unset (in other words: no ft_stop_word_file in my.cnf).
Is there a way to set it (be it with SET GLOBAL or any other command) to use the built-in word set again without needing to restart the server?
Is there a way to set it (be it with SET GLOBAL or any other command) to use the built-in word set again without needing to restart the server?
Yes and no.
No, there isn't.
But you can set it to a custom list of your choice, which can therefore be identical to the built-in word set (you find this in the fine sources). You need to do this only if the variable value happens to be "(built-in)".
Even if you set it from the main list to the identical list, you will have to run a REPAIR TABLE yourtable QUICK to have it digested.
What is the ultimate goal? Would either of these suffice?
Plan A:
MyISAM? It will be going away soon. Perhaps you should set up the table in InnoDB. All the settings for InnoDB are separate from those of MyISAM. There are many subtle differences between the two implementations of Fulltext; the stopword file is just one of them.
Plan B:
Spin up a separate server (or instance on the same server). Set whatever you need it it. Move data from one instance to the other using mysqldump (or similar) with appropriate arguments. If appropriate, make the new instance smaller and use a "where" argument on mysqldump to limit the amount of data copied over.

Match Against no results

I have an issue with a full text search in a MySQL table.
MATCH AGAINST returns no results even I if have 7 records containing the words I'm looking for. What can I do to make it return the rows?
SELECT *
FROM site_plugin_products_cache_texts
WHERE MATCH(item_text) AGAINST ('+your +name' IN BOOLEAN MODE);
No rows.
SELECT *
FROM site_plugin_products_cache_texts
WHERE item_text LIKE'%your name%'
7 rows (0.071 s)
http://sqlfiddle.com/#!9/70c3fa/1/0
Thanks.
Both of those words are included in the Stopwords for MyISAM Search Indexes, which is essentially a list of words to completely ignore in fulltext indexing (as typically they tend to occur too frequently).
The simplest solution would be to switch to InnoDB as your engine, as it has a much shorter list of stopwords. If you need to use MyISAM, you will have to do the following:
To override the default stopword list for MyISAM tables, set the ft_stopword_file system variable. (See Section 5.1.7, “Server System Variables”.) The variable value should be the path name of the file containing the stopword list, or the empty string to disable stopword filtering. The server looks for the file in the data directory unless an absolute path name is given to specify a different directory. After changing the value of this variable or the contents of the stopword file, restart the server and rebuild your FULLTEXT indexes.

Fulltext search, Bypassing word length & stop words? No access to config file

I am using fulltext searching to avoid WHERE column LIKE '%keyword%' and it's disadvantages. However, I have run into a problem with minimum word length setting (client's server is set to 4) and certain stop words. However, my client's server does not give me access to MySQL config. Is it possible to bypass word length and/or stop words somehow in my SQL statements?

MySQL Basics: query execution and case sensitive

I am a newbie to mysql and having some questions on it,
Is there any way to find the execution time of any SQL statement in 'ms' approximation using command prompt (any setting to be done pls specify).
how to make your mysql to allow the case sensitive property (I have to create tables with caps on but after i created, it show the name only in small letters).
You can use EXPLAIN statements to check the execution times.
You can use lower_case_table_names system variable. Use lower_case_table_names=0 on Unix and lower_case_table_names=2 on Windows. However, if you use these settings, make sure you always use the correct case in all your MySQL queries and it can cause issues if you are switching systems from UNIX to WINDOWS or vice versa.
For 2ns you can also check collation. Some details can be found here http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
Check the documentation for more details.

How can I write full search index query which will not consider any stopwords?

I have written a query which will perform Full Text search using full search Index in mysql Table.
But my problem is that when user searches with "to go" then it will not search anything because of stopwords in mysql.
So my question is, how can I write a Full Search query which will ignore the stopwords?
To override the default stopword list, set the ft_stopword_file system variable. (See Section 5.1.4, “Server System Variables”.) The variable value should be the path name of the file containing the stopword list, or the empty string to disable stopword filtering. The server looks for the file in the data directory unless an absolute path name is given to specify a different directory. After changing the value of this variable or the contents of the stopword file, restart the server and rebuild your FULLTEXT indexes.
http://dev.mysql.com/doc/refman/5.1/en/fulltext-fine-tuning.html