0

Im constructing a URL from query items using URLComponents and I want to add some query items as OR conditions rather than AND. Im not sure what the proper terminology for this is. Anyway I would like the following, roughly

website.com/things?param1=thing&param2=thing|param3=thing|param4=thing

but appending query items i can only get

website.com/things?param1=thing&param2=thing&param3=thing&param4=thing

My goal is to check 3 different parameters for the term I pass in, and return any results that match from any of the 3. If I was constructing the url from a string, I could just use a pipe instead of ampersand (I think - please correct me if wrong), but Im using URLComponents and am not sure how to do this.

Perhaps Im going about this incorrectly. I dont have a ton of experience with this. If this is the wrong approach, please point me in the right direction. Im not sure how to word this question appropriately and that makes it hard to search for an answer

Ahmad F
  • 26,570
  • 13
  • 76
  • 124
R.P. Carson
  • 409
  • 4
  • 18

1 Answers1

2

Im not sure what the proper terminology for this is

There is no terminology for it; it doesn't exist. What you're trying to do is nonstandard. There is no such thing as a query item OR condition. Standard separators are semicolon and ampersand, with ampersand used almost universally. You can't use a pipe to separate query items.

Thus, for example, if you paste website.com/things?param1=thing&param2=thing|param3=thing|param4=thing into the parser at http://www.freeformatter.com/url-parser-query-string-splitter.html, it doesn't know what to make of the pipes; it thinks that param2 must be thing|param3=thing|param4=thing.

Thus, URLComponents is not going to insert the pipe for you. Its goal and purpose is to make a valid URL, and you are attempting to make an invalid one.

matt
  • 447,615
  • 74
  • 748
  • 977