Welcome Guest, Not a member yet? Register   Sign In
Pagination on a search page
#1

[eluser]Amenthes[/eluser]
Hi guys, I'm confronted with the following problem. I have a search page that will return large result sets, so a pagination is needed. My question is where should I store the keyword of the search and what should I set "base_url" to in the pagination config array. At a first glance I thought the keyword should be a simple URI segment, but...

1. How do I pass that segment from my search from, which cannot have a POST method as the pagination won't work anymore;
2. What if a user enters a keyword containing a "/"(forward slash)? Basically it will split my segment into two.

I think this is a case where $_GET would do the job but even so, the pagination class won't work because it will append the pagination segment after the GET params. The only solution I can think of is: first, POST the keyword from the form, build the query with that keyword, then generate the base_url of the pagination including an aditional segement - the POST-ed keyword (with any forward slashes replaced by underscores). Then, on any other hit I check if $this->input->post('keyword') returns false, if it does I look for the specific keyword segment and rebuild the query and the pagination. Not very elegant though.

Any suggestions greatly appreciated.
#2

[eluser]LuckyFella73[/eluser]
Hej Amenthes,

maybe there is a better solution to find but have a look at this thread:
http://ellislab.com/forums/viewthread/44845/P15/

Storing the POST data in the db worked for me (a while ago I had the same
problem like you now). The last hint is new to me, looks uncomplicated ..
#3

[eluser]Shadi[/eluser]
check this solution:

http://www.ellislab.com/forums/viewthread/51505/

Regards;
#4

[eluser]barbazul[/eluser]
[quote author="Shadi" date="1189467414"]check this solution:

http://www.ellislab.com/forums/viewthread/51505/

Regards;[/quote]

That's indeed a great pagination class.

Regarding the keywords submitted by the user you could use a similar approach to the one used in this forum:

When you submit the search form you are directed to a page saying you will be redirected to the result, what's actually going on is that the search is being made, then the results are cached and assigned a name which is normally a hash of the submitted keywords. You are then redirected to a page that actually shows the cached result using the hash as a parameter in the uri.

For example, suppose you search for "code igniter" within this forum.
You are redirected to a page called "do_submit" stating that you will soon be redirected.
A couple of seconds later you arrive at this page:

http://ellislab.com/forums/search_result...12acee4d6/

which is a simple url ('simple' because it can be copy and pasted to get the same results page)

now, when you go to the next page, the hash gets appended somewhere in the url, allowing you to navigate through the same set of results
#5

[eluser]Muser[/eluser]
I'm really interested for knowing how I can got work this...

How can you get results cached? Where are cached? In database or in filesystem?

And when results are cached, and wildcard hash param is passed, how can you retreive cached results?

I can't imagine "do_submit" code... Tongue

Please, show me!
#6

[eluser]taewoo[/eluser]
Don't cache.

Have two controllers -
A) "Receive" the actual search form parameters via $this->input->post . This redirects to the second controller via

Code:
redirect('search/query/QUERY_STRING/')

B) your controller 'search' has a method 'query' that takes the QUERY_STRING and does your search thing.


The on the pagination, use 'search/query/PAGE_NUMBER' instead of using the 1st controller.

Thus no need for caching... plus this is prettier and people can book mark it.
#7

[eluser]taewoo[/eluser]
As far as allowing URL encoded strings in your query string...read this post http://ellislab.com/forums/viewthread/72933/
#8

[eluser]Muser[/eluser]
Taewoo,

Your suggestion seems interesting! Now I'll try it! You have convinced me

Thank you :lol:

P.S.: However, it intrigues me how a search like this forum would be made :long:
#9

[eluser]taewoo[/eluser]
Yeap. That's how I do it in my site.
Go to [url="http://www.redmol.com/"]http://www.redmol.com/[/url] and see

1) the search form and see which controller it posts to
2) what the resulting controller/method is...
#10

[eluser]Amenthes[/eluser]
My solution back then was to store the posted search term in a session variable, anyways...

Quote:As far as allowing URL encoded strings in your query string...

Don't you guys feel a need to... "$_GET" an easier solution? Why should we reinvent the wheel? Which by the way, seems to have corners...

I think that, at least for user provided input like search terms, $_GET is the best solution you can get.




Theme © iAndrew 2016 - Forum software by © MyBB