2

I am creating an advanced search page where there are about 20 search fields for a user to filter their search. My question deals with the query string, Is it standard web development practice to have say 20 parameters in a querystring?

The search results display large tables of data. Is there an alternative that still uses HTTP GET(querystring), if it is not standard? I would like the users to be able to bookmark their searches.

4
  • check out stackoverflow.com/q/4203686/866172
    – Jalayn
    Commented Apr 3, 2013 at 12:52
  • What kind of search fields are they? Check boxes/radio buttons/drop-downs? Free text? This might influence your solution.
    – Andy Hunt
    Commented Apr 3, 2013 at 12:52
  • They are drop downs and text fields
    – Rayshawn
    Commented Apr 3, 2013 at 14:07
  • use POST and for book marks share a GET URL with a code that points to the same search with pre filled values. So the search values go to a db with the key shared in the short GET URL
    – tgkprog
    Commented Apr 12, 2013 at 10:51

4 Answers 4

2

I would not worry about having this many parameters in a query. There is no restriction on number of parameters, only total length of the URL (as mentioned by others). Long queries with lots of parameters are commonly used by big-name websites. For example, it is easy to construct a 15 parameter query in Google Maps.

As long as GET makes sense for your case, and you don't have to worry about the character limit, I would use it.

Interestingly, Google Maps also doesn't worry about breaking the 2000 character limit. Here is the URL it generated for my tour of places with long names in the Philadelphia area:

https://local.google.com/maps?saddr=Philadelphia+International+Airport,+Essington+Avenue,+Philadelphia,+PA,+United+States&daddr=Philadelphia+Archery+%26+Gun+Club,+Ellsworth+Street,+Philadelphia,+PA,+United+States+to:Philadelphia+Museum+of+Art,+Benjamin+Franklin+Parkway,+Philadelphia,+PA,+United+States+to:Northeast+Philadelphia,+Philadelphia,+PA,+United+States+to:Philadelphia+International+Airport,+Essington+Avenue,+Philadelphia,+PA,+United+States+to:Philadelphia+Airport+Florist,+MacDade+Boulevard,+Philadelphia,+PA,+United+States+to:Philadelphia+Museum+of+Art,+Benjamin+Franklin+Parkway,+Philadelphia,+PA,+United+States+to:Philadelphia+Family+Court,+South+11th+Street,+Philadelphia,+PA,+United+States+to:Philadelphia+Museum+of+Art,+Benjamin+Franklin+Parkway,+Philadelphia,+PA,+United+States+to:Erawan+Thai+Cuisine,+South+23rd+Street,+Philadelphia,+PA,+United+States+to:Four+Points+by+Sheraton+Philadelphia+City+Center,+Race+Street,+Philadelphia,+PA,+United+States+to:Philadelphia+Museum+of+Art,+Benjamin+Franklin+Parkway,+Philadelphia,+PA,+United+States+to:Philadelphia+International+Airport,+Essington+Avenue,+Philadelphia,+PA,+United+States+to:Philadelphia+Streets+Department,+Arch+Street,+Philadelphia,+PA,+United+States+to:Oak+Lane%2F+East+Oak+Lane,+Philadelphia,+PA,+United+States+to:Philadelphia+International+Airport,+Essington+Avenue,+Philadelphia,+PA,+United+States&hl=en&sll=40.283716,-77.036133&sspn=3.582578,6.773071&geocode=FZxxYAIdUcqD-yHY0zdGlBUuPikvg6lgZsTGiTHY0zdGlBUuPg%3BFeBcYQIdzSyF-yGcj_mKAfhviSnVvLzvHsbGiTGcj_mKAfhviQ%3BFS3UYQIdhNSE-yHTwCkDIXYoiyn_kKhF5sXGiTHTwCkDIXYoiw%3BFRVmYwIdt4yH-ykvmB-AjLPGiTH60vEMkAhnrA%3BFZxxYAIdUcqD-yHY0zdGlBUuPikvg6lgZsTGiTHY0zdGlBUuPg%3BFaKWYAIdt8iD-yFsINr-eokAkSmfV6fdfcPGiTFsINr-eokAkQ%3BFS3UYQIdhNSE-yHTwCkDIXYoiyn_kKhF5sXGiTHTwCkDIXYoiw%3BFeeZYQIdsCuF-yEClZG3nPycxilx2ebjKMbGiTEClZG3nPycxg%3BFS3UYQIdhNSE-yHTwCkDIXYoiyn_kKhF5sXGiTHTwCkDIXYoiw%3BFYGdYQIdRN-E-yFe7_1dh5lMoCmBMp8cSMbGiTFe7_1dh5lMoA%3BFSCuYQId9imF-yF-Sw5cubLO2il5juueK8bGiTF-Sw5cubLO2g%3BFS3UYQIdhNSE-yHTwCkDIXYoiyn_kKhF5sXGiTHTwCkDIXYoiw%3BFZxxYAIdUcqD-yHY0zdGlBUuPikvg6lgZsTGiTHY0zdGlBUuPg%3BFWipYQIdwwqF-yH_vQ3XcJYw_Snrjd4cMsbGiTH_vQ3XcJYw_Q%3BFTInYwIdNKKF-yk9j724FbfGiTFK_xFG6xNTDQ%3BFZxxYAIdUcqD-yHY0zdGlBUuPikvg6lgZsTGiTHY0zdGlBUuPg&oq=phil&dirflg=ht&doflg=ptk&mra=ls&t=m&z=12

This URL also works in recent versions of Internet Explorer, so perhaps this limit no longer exists. The information about the IE limit, linked above, goes back to a source from 2006, so the limit might have been gone for a long time.

Update: after further testing, I discovered that Chrome (!) chokes on this long URL. So maybe you should worry about it!

2
  • that is funny that it failed on chrome! but it looks like they use ajax once you get a smaller URL and write a larger text string in chrome
    – tgkprog
    Commented Apr 12, 2013 at 10:46
  • @tgkprog, I found it rather ironic. Also mystifying. Who builds a modern application with an arbitrary 2000 character limit on something that has no specified limit? I can understand why a piece of software with a long history, like IE, might have that as an artifact of the days when 8MB was a lot of RAM, but why Chrome?
    – user82096
    Commented Apr 12, 2013 at 10:49
1

It does seem a little odd to have so many items, I would have suggested using a post and putting the content in the data sent.

You however said you want to be able to bookmark the results page so I think you need to keep it in the query string as you're doing. Do consider however that the query string has a max length in most browsers, e.g. IE is limited to 2048 characters, which might be a problem. See - https://stackoverflow.com/questions/812925/what-is-the-maximum-possible-length-of-a-query-string

1
  • to book mark can make a shorter URL keeping a code in your a public data base that points to a page with the search values pre filled and results shown
    – tgkprog
    Commented Apr 12, 2013 at 10:50
0

As explained in a related SO question, there's technically no limit to the length of a URI, however IE 8 and below only supports up to 2083 characters, so if there's a possibility that your search page could generate a URL longer than that, you should implement bookmarking another way.

This page has some suggestions for how to work around the practical URL length limit while still allowing bookmarking:

  1. If your field names take up too much space, use a fixed field order instead
  2. Squeeze out any field that doesn't really need to be bookmarked
  3. [A]void large decimal numbers - use only as much accuracy as you must, and consider a base-64 representation using letters and digits
  4. In extreme cases, consider using the gzip algorithm to compress your pretty but excessively long URL. Then reencode that binary data in base64 using only characters that are legal in URLs
  5. An alternative is to store the state information in a file or a database. Then you can store only the identifier needed to look up that information again in the URL
0

Standard practice would generally be to allow the parameters to all be in the query string. However, you find that the browser limit is being exceeded, you do need to figure out an alternative system.

A possible solution would be:

  • use HTTP POST body to submit the arbitrarily lengthed data
  • cache these search parameters, and generate a unique ID for it
  • issue a browser redirect of the form http://[your_query_url]?query_id=[generated_id]
  • now, just make sure that you [your_query_url] can translate the ID into the query using the cache to seamlessly generate the response

To the user, this will be a seamless search, and they now will have a bookmark-able page. Depending on other real world requirements that you may have, this could be optimized to some extent to meet your needs, but it is a simple starting point that gets around browser limitations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.