0

I am currently busy creating a search function that queries a user input string against certain row in a mysql table.

This is what the code looks like so far:

$space_separated = implode(" ", $keywords_array);

$dataQuery = "SELECT id, `desc`, price1, pack, measure, quantity
              FROM products
              WHERE MATCH (`desc`)
              AGAINST ('".$space_separated."' IN BOOLEAN MODE)";

It is not quite providing the desired functionality. I am aware that in boolean mode, i forfeight the use of scoring. But my problem is that this code does return partial matches on any set word.

An example of this would be if a user was searching for "chocolate" and they searched "olate", no match will be returned. How would I work around this?

@Mark

Were you suggesting this?

$dataQuery = "SELECT id, `desc`, price1, pack, measure, quantity
              FROM products
              WHERE MATCH (`desc`)
              AGAINST ('".$space_separated."' IN BOOLEAN MODE)
              OR MATCH (`desc`)
              AGAINST ('".$space_separated."')";
4
  • 1
    add ... or match(...) to do a natural language match as well (do the fulltext again, but without 'in boolean mode')? Commented Aug 26, 2011 at 19:55
  • @Mark Thanks for your input with this, please see the edit in my post. Is that what you were referring to? Commented Aug 26, 2011 at 20:19
  • 1
    yeah, pretty much. but as golez points out below, fulltext only matches on full words, unless you add wildcards. Commented Aug 26, 2011 at 20:21
  • @Mark Is it possible to use boolean functionality while being able to obtain result ranking using natural language search? (it didnt work btw, as you repointed out, GolezTrol has a point) Commented Aug 26, 2011 at 20:23

1 Answer 1

1

FULLTEXT searched for whole words only. You can specify a wildcard * behind a part of the word, but not before. So choco* will match chocolate', but*olate` will not.

Also, default matching uses or for comparison. If you want to match all keywords, add a + before each keyword.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the reply, I am searching for a work around or a better option with this function though. I did think of the wildcard approach, but came to the same conclusion. Any other ideas?
You could use separate search utilities, like Sphynx. You could also write some code yourself. If you split a text in separate words, you can create an index for that. Then, you can also split up those words to index only parts of it. That way, you can do an exact match for the words or for parts of a word. It will be some work, though, so you might better try out some third party solutions first.
Thanks for that, it makes sense. I will check out Sphynx. I want to add some kind of synonym function, which sounds sort of the same. I'll work on it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.