Against not returning score - mysql

There is something wrong with this query? This one works sometimes and sometimes not. For example with the word 'seven' it doesn't return any score, but i know that it appears on 29 rows at least in the body however it return as score 0.
With other words it work ok but not with this one. Anyone know why or have a different solution to sort it by relevance?
SELECT *,
( (MATCH(articles.name) AGAINST('seven'))*5 +
(MATCH(articles.subtitle) AGAINST('seven'))*3 +
(MATCH(articles.body) AGAINST('seven'))) AS search_score
FROM articles
LEFT JOIN matches ON articles.match=matches.id
ORDER BY search_score DESC
EDIT: I noticed that 'seven' is a stop word. There is other way to do this? stopwords

Add COALESCE(value,0) around each score.

Problem
If the word is too common, i.e. occurs in 50%+ of the rows, MySQL considers it a STOP-word and will not match against it.
Then there's the stop-word list (which you've already noticed)
See: http://dev.mysql.com/doc/refman/5.5/en/fulltext-stopwords.html
Solution
This answer: where to edit mysql fulltext stopword lists?
Tells you how to override/replace the default stop word list.
Here's the link to the MySQL docs page: http://dev.mysql.com/doc/refman/5.5/en/fulltext-fine-tuning.html

Related

match against doesn't work with the word "when"

When desc contains the string: zoom when wifi dies for 1 second
Query 1:
SELECT * FROM `pics` WHERE MATCH(title, desc, owntags, usertags) AGAINST('+zoom* +wifi*' IN BOOLEAN MODE)
No problem, I get the row!
Query 2:
SELECT * FROM `pics` WHERE MATCH(title, desc, owntags, usertags) AGAINST('+zoom* +when*' IN BOOLEAN MODE)
No results! So when belongs to sql commands.
So how to solve this?
You need to learn some basics about full text search. One very important concept are stop words. These are words that are not included in the full-text index, because they are so common or add little meaning (at least from the perspective of the person who created the stop word list . . . a famous problem involves the band The Who).
The word 'when' is a common stop word and a default stop word in MySQL (see here and here). So, it is not being indexed.
You will need to recreate your full text indexes, either removing all stop words or using your own custom list.

MATCH AGAINST in MySQL don't work

I have a problem with FULLTEXT search in MySql.
I create query:
SELECT searchTag, MATCH (searchTag) AGAINST ('after party') as score FROM post WHERE MATCH (searchTag) AGAINST ('after party') ORDER BY score DESC
Its result:
1. we,like,to,party 3.6987853050231934
2. f,w,g,party 3.6987853050231934
3. after,party,tooka 3.657205581665039
Why number 3 have lower score if it have two words searching?
after is a stop word. It is ignored by a FULLTEXT MATCH query.
Basically, the word "after" is so common in the English language that including it in a query is semantically meaningless.
Think of it this way: imagine a query against the word "a". There are so many sentences which use the word "a", that a match against them really won't provide you with anything useful.
In this post, all of the sentences reference the word "a".

mysql fulltext boolean search with asterix

I have a query like below:
SELECT prd_id FROM products WHERE MATCH (prd_search_field)
AGAINST ('+gul* +yetistiren* +adam*' in boolean mode);
This doesn't return the rows including 'gul'.
http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html
The document says this.
Then a search for '+word +the*' will likely return fewer rows than a
search for '+word +the':
The former query remains as is and requires both word and the* (a word starting with the) to be present in the document.
The latter query is transformed to +word (requiring only word to be present). the is both too short and a stopword, and either condition is enough to cause it to be ignored.
So as I understood the too short word condition must not be applied in my situation since I use * after each word. What's wrong with this?
As a solution I use the below query but since it's slow, I need to find another solution. Any idea would be appreciated? Thanks in advance..
SELECT prd_id FROM products WHERE 1 AND MATCH (prd_search_field)
AGAINST ('+yetistiren* +adam*' in boolean mode) AND prd_search_field
LIKE '%gul%';
As a note ft_min_word_length=4 as default in all shared hosting environments, and I cannot change it.

Issue with Singular Words and MySQL Fulltext Searching

I've setup a fulltext search to listen on the title and description columns for my blog articles table in MySQL. The SQL that I use to search the table is as follows:
SELECT title,description,publish_date FROM table WHERE MATCH(title,description) AGAINST('cats','dogs') ORDER BY publish_date DESC LIMIT 100
This works (for 'dogs' and 'cats'), but when I use the singular ('dog' or 'cat') then I find no results. Not sure why this is going on, I've tried different variations like "+dog, +cat" and tried including IN BOOLEAN MODE as well ... Nothing works. And Yes I am sure that there are other words in the description column that are "dog" and "cat" as well as their plural versions.
How can I get singular words to work with MySQL?
The default minimum word length for full-text searches is 4 characters.
You'll need to change that in the server configuration. See here for some info on how to do it.
why don't you try something like this:
SELECT title,description,publish_date, MATCH(title,description) AGAINST('search') AS score FROM table WHERE MATCH(title,description) AGAINST('seacrh') ORDER BY score LIMIT 100;
maybe this will help but will not work propertly with one word

MySQL FullText search?

I am working on search functionality in my website. I want to provide a best search mechanism to users. I am using PHP/MYSQL.
Let's say user searched for "sport".
I have 30 records having word "sport" and 5 records having word "sports" but when I am searching for sport then following query only returns the result 30 who have the word "sport". But actually I think the best way to provide good search result is to display all the 30+5 records, all the records having sport or sports.
SELECT DISTINCT p.id, p.title, p.descr, p.tags FROM pdata p WHERE MATCH (p.title, p.tags, p.descr) AGAINST ('sport')
Please tell me some articles or some tips & tricks using which I'll be able to provide a good search functionality.
...MATCH (p.title, p.tags, p.descr) AGAINST ('sport*' IN BOOLEAN MODE)
May do the trick.
Edit, the MySQL documentation is an excellent resource for these kind of problems! :)
Just use the % wildcard on your search strings. This will allow any words formed by the search string to be matched. Sadly you will need to be in Boolean mode for this wildcard to work. Also all search strings must be greater then 3 characters in order to show up using full text search. this can be changed in the mysql system settings, but the default is 3.
In your case I would make the following query:
SELECT p.id, p.title, p.descr, p.tags
FROM pdata p WHERE (p.title LIKE
'%SPORT%' OR p.tags LIKE '%SPORT%' OR
p.descr LIKE'%SPORT%')
This query would find any articles which cover sportmagazines , summer-sports ect ect.