Jump to content

adding a site search


wrathican

Recommended Posts

Heya people

 

Im trying to add a search function to my website. ive got a few ideas, but not sure on how to implement one or two.

 

The simplest way is obviously going to be to use the mysql like clause.

with this i have two options:

1: search for full search term and return all results that contain the exact phrase.

2: explode the search term and use multiple like clauses and return all results that contain any of the derrived terms.

 

This seems to be unhealthy for a few reasons.

1: a user could search for 'the' and each entry containging the word 'the' would be returned.

2: a user could use keywords and search for something like 'loop php'. so wither all results containing the phrase 'loop in php' or 'loop' or 'php' or 'in' would be returned using the above two methods.

 

this could get messy and not very reliable.

 

i had another idea:

remove any words that are not keywords, eg: 'a', 'and', 'the', 'a'... etc

this could be done with a simple preg_replace, but i see the 'bad' words array being pretty huge.

then search using multiple like queries.

 

are there better ways?

would any of these be efficient?

 

Thanks for your help in advance.

 

Wrath

Link to comment
https://forums.phpfreaks.com/topic/133351-adding-a-site-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.