Mysql search with string and number using MATCH() AGAINST() not working - php

everything ok?
I'm doing this Query:
SELECT model, MATCH (model) AGAINST ('+a3*' IN BOOLEAN MODE) AS relevance
FROM models
WHERE MATCH (model) AGAINST ('+a3*' IN BOOLEAN MODE)
ORDER BY relevance DESC
LIMIT 30
But it does not return anything ...
If I just use letters or just ok numbers, but if merge letters with numbers returned nothing.
In my table I have:
A3 1.6 3p
A3 1.8 5p Aut.
and several others.
Can anyone help?

Set ft_min_word_len = 1 in ini file of Mysql.
Then restart Mysql
and repair table
REPAIR TABLE test QUICK

Related

MySQL: Help to search each word in multiple columns as case insensitive

I have a table that contains: product, cost, comment.
Id product cost comment
1 Tires Rex 10 Fast movement good quality
2 Bone Maxx Centri 110 Clean and soft movement
3 Engine damaged 20 Damaged
The outcome I want: User can searches multiple words and the query has to find the items with those words as case insensitive.
For example, user searches: Buy clean tires for cars
The query output has to show products with Id 1 and 2.
Why?
Because the word Clean matches the comment in product with id 2
Because the word tires matches the product with id 1
I tried with:
SELECT * FROM `inventory` WHERE MATCH (product) AGAINST ('Buy* clean* tires* for* cars*' IN BOOLEAN MODE);
But that only works for 1 column and is case-sensitive.
I want it searches in multiples columns as case-insensitive.
Any help will be appreciated!
Use the following query, it's tested and returns first 2 rows:
SELECT * FROM `inventory` WHERE MATCH (product, comment) AGAINST ('Buy* clean* tires* for* cars*' IN BOOLEAN MODE);
I just updated my system using yum update and now is working fine.
Maybe that was the problem.
The problem now is that, is case sensitive. If I search "Clean" it works but if I search "clean" it does not.

Mysql Select Query with match and against issue

This is my code to perform a search
SELECT d.deal_id,
d.deal_title,
d.friendly_url
FROM wp_deals AS d
WHERE MATCH (d.deal_title) AGAINST ('Historic China eight day tour' IN BOOLEAN MODE)
GROUP BY d.deal_id
It works fine.and give 14 results.
one of them is
Great Sandy Straits two night Natural Encounters Tour for two with sunset cruise & more. Up to $1,071 off!
But when I search for "with" or "more" it becomes
SELECT d.deal_id,
d.deal_title,
d.friendly_url
FROM wp_deals AS d
WHERE MATCH (d.deal_title) AGAINST ('more' IN BOOLEAN MODE)
GROUP BY d.deal_id
SELECT d.deal_id,
d.deal_title,
d.friendly_url
FROM wp_deals AS d
WHERE MATCH (d.deal_title) AGAINST ('with' IN BOOLEAN MODE)
GROUP BY d.deal_id
and does not give any result although with and more both are their. I am not an expert with this type of search query.
But
When i search with "tour" that is also their it works fine.whats going on their.
could not understand as "tour","with" and "more" all contains four letters and also their in title.
You People are Genius..
What you suggest so it will workout.
Thanks in advance.
In Boolean full-text searches the stopword list applies and common words such as “some” or “then”... are stopwords and do not match if present in the search string : http://dev.mysql.com/doc/refman/5.5/en//fulltext-boolean.html
Stopword list : http://dev.mysql.com/doc/refman/5.0/en/fulltext-stopwords.html
The best known solutions are disable the list or add / remove values ​​from it : How to reset stop words in MYSQL?
Also :
SELECT d.deal_id,
d.deal_title,
d.friendly_url
FROM
wp_deals AS d
WHERE MATCH (d.deal_title) AGAINST ('+more*' IN BOOLEAN MODE)
GROUP BY d.deal_id

MySQL fulltext search Boolean mode confusion

I'm getting a bit confused when trying to set up a search utilizing fulltext search in boolean mode. Here is the query I'm using:
$query = "SELECT *,
MATCH(title) AGAINST('$q' IN BOOLEAN MODE) AS score
FROM results
WHERE MATCH(title) AGAINST('$q' IN BOOLEAN MODE)
ORDER BY score DESC";
When I run a search for +divorce+refinance, the results returned are:
1) Divorce: Paying Off Spouse = Rate/Term Refinance
2) Divorce - What to Look Out For Regarding Divorced Borrowers
Am I right in thinking that the second result should not be appearing, as it does not have both words? If not, how can I create that functionality?
Maybe I am mistaken, but if you search this string +divorce+refinance you get a weird result. If you want to search both words, your should search for +divorce +refinance (with a space between).
I tested it and it returns only one row:
Divorce: Paying Off Spouse = Rate/Term Refinance
Your problem relates to the create a prioritized boolean query and for this type of query one has to go in depth of Boolean search and to now how the Boolean search is performed. In simple words let me explain you why the second number result of result is shown.
Once should first understand what does Boolean means in programming?
It means either condition is true or false i,e 0 to 1.
Now let me explain for the Boolean search is performed? You have given two words. Let us search the row by row in Boolean mode. Search engine start and searches the row by row now where ever the First word is found, it makes the record true and give score as 1 to the rows in which the first word is found and also prepare the numbers of words found in the row.
Now it moves the next word and do the same process gives the record True and makes a list of records wherever the word is found and also prepare the number of words found in the row.
Now there are two rows of results are available and they are clubbed and with the priority is given to the words with the maximum number of words and row here is the main problem lies.
Example
First >>> total nos. >> Second >> total nos. >>> Final >> row
Word >>> Results >> Word >>>> of words > > > Results >>no >>Answer
1 >>>>>>>> 2 >>>>>>>>1>>>>>>>>>1>>>>>>>>1.33>>>> 1 >>> 1.33
0 >>>>>>>> 0 >>>>>>>>2>>>>>>>>>2>>>>>>>>1.25>>>> 2 >>> 1.25
0 >>>>>>>> 0 >>>>>>>>1>>>>>>>>>0>>>>>>>>1.25>>>> 3 >>> 1
While clubbing two results lists when true added with false then result is true, as if you add 1 + 0 = 1 and the results are should with value more than 1. So, while scoring the relevancy to the words found it is always found that the search engine shows the results where it found any word.
Scoring relevancy queries are done in two types either ignore the scores which are equal to one and only do calculations on the records who's score is greater than 1. Second is to make such a query that it never shows the records equal to one. As in your case you can so the below things also to get the correct results for two words:
SELECT *, ( (1.3 * (MATCH(title) AGAINST ('+term +term2' IN BOOLEAN MODE))) + (0.6 * (MATCH(text) AGAINST ('+term +term2' IN BOOLEAN MODE))) ) AS score FROM results WHERE ( MATCH(title, text) AGAINST ('+term +term2' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC;
I know that using the word HAVING make the query little slow but there is no other solution available. Hope this solves your query.

MySQL Fulltext won't find rows

I've got a car searching website and when I set up the search system it failed to give any dynamic searching. For instance, it's got 500 cars on their and ~5 are 'Toyota Ist'.
So when I search 'Ist' I get no results. (See query)
SELECT *,MATCH(aTitle, aDescribe, aCarModel, aCarWheels, aCarStereo, aCarIntTrim, aCarTrans, aCarDrive, aCarFuel, aCarPlate, aCarColour) AGAINST('toyota ist' IN BOOLEAN MODE) AS score FROM at_auction WHERE status = '1' AND aCarYear >= 1992 AND aCarYear <= 2012 AND startBid >= 0 AND startBid <= 20000 AND MATCH(aTitle, aDescribe, aCarModel, aCarWheels, aCarStereo, aCarIntTrim, aCarTrans, aCarDrive, aCarFuel, aCarPlate, aCarColour) AGAINST('toyota ist' IN BOOLEAN MODE) AND closeTime >= '201201060842' ORDER BY opt_feature DESC, score DESC, score DESC LIMIT 0,10
But if I search 'Toyota Ist', i'll get a whole lot of Toyota Results. And the Ist car isn't neccessarily high in the list.
So the problem underlying is how do I set it up so that if someone searches just one word, say the cars model, it'll return the row... and how it can return the row if they search with multiple words like 'toyota camry', although that actually seems to work.
The MATCH fields are all FULLTEXT and aCarModel etc store the cars model and they're usually just one word like 'Ist' or 'Camry'.
Thanks.
If over 50% of the cars are "Toyota", then "Toyota" will be ignored in the search. Also, the FULLTEXT doesn't index words under 4 letters.
50% limit and other tuning bits about FULLTEXT
http://dev.mysql.com/doc/refman/5.1/en/fulltext-fine-tuning.html
Minimum word length
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_ft_min_word_len

Optimizing auto-complete FULLTEXT SQL query

I have the following query which is used in order to do an auto-complete of a search box:
SELECT *, MATCH (screen_name, name) AGAINST ('+query*' IN BOOLEAN MODE) AS SCORE
FROM users
WHERE MATCH (screen_name, name) AGAINST ('+query*' IN BOOLEAN MODE)
ORDER BY SCORE DESC LIMIT 3
I also have a FULL TEXT index on screen_name & name (together). When this table was relatively small (50k) this worked great. Now the table is ~200k and it takes seconds(!) to complete each query. I'm using MySql MyISAM. Is this reasonable? What directions might I check in order to improve this as surely it doesn't satisfy the needs of an auto-complete query.
MYSQL Match against is really slow, you should look into alternatives like Sphinx Search Server.

Categories