SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What to do with search results and how

    I've been trying to figure out what is considered best practice(s) when it comes to storing, retrieving and cleaning up search results in a PHP/MySQL combination. I haven't found too many in-depth discussions about this on the internet, so I've come up with my own solution, and I hope some of you more experienced coders could offer some input.

    First of all, I want people to be able to open a new tab in the same browser to conduct a new search while keeping older search results in the first tab (in order to compare the results or whatever). So session id can't be used to keep track of search results. Instead each search need a unique id, and I've chosen time. At the end of each search the variable $t is assigned current time, i.e. $t = time(). The search results are then saved in a plain textfile named with a combination of session id and $t to ensure its uniqueness. The total number of hits and some other search-related data are stored in session variables such as $_SESSION[$t]['no_of_hits'], $_SESSION[$t]['query'].

    On each page of results I show, say, 10 hits and 10 links to other pages. The URLs for the links to the other pages contain page number and the time of the search (i.e. "...?t=1378893448&p=2...") which are used to identify the right file and retrieve the right contents of it (after checking if there is such a file).

    As for cleaning up, I let the users help doing that. After each search a check is made to see if there are any search-result files older than 1 hour. And if there are, they are deleted.

    Does anyone see any problems with this, or have any suggestions for improvements or alternative (better) solutions?
    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have never used tabs so I may be way off base, but here goes.

    When you show the user some results (tab 1), have a button that says "Do New Search" or something, which triggers a new tab via the target attribute. Using the same script, you generate a new search on this new tab per their requirements. And so on.

    Is that what you need? No problem retaining data since the data is still on the old tab. As for cleaning up, why not just let the user close the tabs he doesn't want anymore? Or you could set a cookie when the "Do New Search" button is clicked that saves the name of the current window (you'd have to establish that during 'onload' perhaps) and each time you start a new tab you could look for these cookies and do your timed delete thing still.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply, but it seems like my questions were a bit off, perhaps, putting too much focus on tabs. That was just an example. What was important was that more than one search should be possible within the same session. If the user opens a new tab or a new window and how (s)he does it doesn't really matter.

    So I'll try to be more clear.

    What is the best/most common place to temporarily store search results? In a file, in a database, in a session variable (probably not) or elsewhere ...? If a file, what sort of file and what format? Are there any faster/better ways than a serialized array in a .txt file? And if I need to store more than one search result for the same session, what is the best/most common way used to keep track of these in order to serve the right hits at the right place? ...

    That's the kind of very basic questions I'm really asking. I'm sure there must be some generally accpeted standards for these things, since there are millions of web sites with integrated searchable databases but hardly millions of different solutions (although some variation depending on the type and amount of data involved, of course).

    I understand if nobody wants to write a basic tutorial here, but if someone could point me towards a good one I'd be very happy.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •