Jump to content

A better way to search?


K_N

Recommended Posts

Right now I'm using a query like

 

SELECT * FROM `table` WHERE title LIKE '" .$searchterms. "' ORDER BY id"

 

but this only returns exact results in most experiences. I need to be able to say, have "This is something to search for" in the database, and have the search return it in the results even if I just searched for "This is" or "This is something" or "Something to".

 

(Obviously I'm going to filter out common words in the PHP later on, I just need the right SQL syntax right now)

 

What else can I use to search?

Link to comment
Share on other sites

SELECT * FROM `table` WHERE MATCH `title` AGAINST('{$searchterms}' IN BOOLEAN MODE) ORDER BY id asc

 

You should ALWAYS look to MATCH AGAINST for your queries to start with, if you cant do it with that use other query types

 

If you have an immense database like me, create an inverted index that way your only searching the word and not the whole document, and its SUPER effective

Link to comment
Share on other sites

SELECT * FROM `table` WHERE MATCH `title` AGAINST('{$searchterms}' IN BOOLEAN MODE) ORDER BY id asc

 

You should ALWAYS look to MATCH AGAINST for your queries to start with, if you cant do it with that use other query types

 

If you have an immense database like me, create an inverted index that way your only searching the word and not the whole document, and its SUPER effective

Ahh, thank you.

 

This database only has about 10k entries, is that something I should use an inverted index for?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.