I am building a program that uses Bing's search API and common lisp with the Drakma library to display some results but for some reason have an error when sending a longer length query It doesn't display any of the results at all. It works for shorter length queries. I am using a temp account for this question. I have the following code.
(defun get-rid-of-spaces (var)
(cl-ppcre:regex-replace-all " " var "%20"))
(defun print-bing (search-term)
(format nil "https://api.datamarket.azure.com/Bing/Search/v1/Web?Query=%27~a%27&Options=%27DisableLocationDetection%27&$format=json&$top=1" (get-rid-of-spaces search-term)))
(defun drakma-bing (search-term)
(drakma:http-request (print-bing search-term)
:basic-authorization
'("bob.hammerston@mailinator.com" "L2gbaj+s1/KW/+ifAa9HrP0C1/kClpF4InH48Lw8UNc")))
(defun convert-to-string (response)
(map 'string #'code-char response))
And then I call this but it only works for short search terms and I can't figure out why. This doesn't work:
(convert-to-string (drakma-bing "what is the largest man in the world"))
But this does
(convert-to-string (drakma-bing "what is"))
Any idea why?
Thanks.
Edit:
I tried encoding the print-bing function by hand instead of using that function with a longer string and it still doesn't work so there must be an error with Drakma. I tried typing the domain into the web browser by hand and it works so that is why I think the error is with Drakma.
You need to use +
instead of %20
for spaces.
(defun get-rid-of-spaces (var)
(cl-ppcre:regex-replace-all " " var "+"))