Welcome Guest, Not a member yet? Register   Sign In
Best way to implement search?
#1

[eluser]Mateo1041[/eluser]
Here's my dilemma:

* I want to use form validation
* I want the user to be able to bookmark the search results page or share with friends

What's the best way to go about this? CodeIgniter doesn't support GET, so I'm not able to pass parameters via the URL line by default. I tried the following, but it didn't work:

http://ellislab.com/forums/viewthread/56389/#277621

I could use JavaScript to rewrite the action when the submit button is pressed, but then I don't see a good way to use form validation. :-( On the other hand, I'd hate to get rid of form validation because the rest of my website already uses it and I'd like to be consistent.

Any recommendations would be greatly appreciated.
#2

[eluser]Craig A Rodway[/eluser]
I do a similar thing in a website I'm currently working on, except it's the search parameters that are stored and not the exact results for a given query - but it could be easily modified to do that.

Once the search form is submitted and validated as normal, I run the serialize() function over the posted form data. I then store this in a database table with an auto-increment primary key field. I get the ID, and redirect to a /search/results/$id page. The ID is looked up in the database, unserialize() is ran to get the original form data into an array, and the database search is then carried out using this data and results displayed.

When my underlying data changes, the results for a given search will also be up to date.

If it is definitely the result data you want to be the same, regardless if it has since changed, then it might be best to look into a cache library, such as MP_Cache to store the results. Essentially you would run the query, get the results, and then check if the results are in the cache using a generated hash (md5 or sha1). If the results aren't in the cache, store them; otherwise retrieve them from the cache to show.
#3

[eluser]Mateo1041[/eluser]
Thanks, Craig! A unique ID/hash is a great idea and would use form data that's already previously been validated. I may even run a cron that automatically prunes my DB table to get rid of old results after a period of time. I plan to broaden the scope of this to other form result data as well.

I'm only interested in storing the query and not the result. The result can change.




Theme © iAndrew 2016 - Forum software by © MyBB