INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Problem with MCWS database search / searchstring containing "&"  (Read 1897 times)

winniew

  • World Citizen
  • ***
  • Posts: 102
Problem with MCWS database search / searchstring containing "&"
« on: January 04, 2015, 03:38:22 am »

I have a problem with the MCWS database search for files.
I am trying to retrieve a (filekey-)list of all Image-Files in the library for a given [Artist].

Code: [Select]
http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Frank Zappa] [Media Type]=[Image]&Action=Serialize&qrOqNbnbThis works as expected for [Frank Zappa]:
response is: 2;40;-1;28061958;28061961;28061963;... (40 filekeys = OK)

Code: [Select]
Logfile:
..
0009438: 7216: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Files/Search?Query=[Artist]=[Frank%20Zappa]%20[Media%20Type]=[Image]&Action=Serialize&qrOqNbnb
0009454: 7216: Database: CSearchFilesHelper::GetResults: Search: [Artist]=[Frank Zappa] [Media Type]=[Image]; Elapsed ms: 6,698
0009454: 7216: Sharing Plugins: JRWebService::Process: Finish (16 ms)
..

But if the [Artist] contains a "&" I get a wrong response:
Code: [Select]
http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck & Patti] [Media Type]=[Image]&Action=Serialize&qrOqNbnbresponse is: 2;93;-1;24119834;3152837;3152838; ... (93 filekeys = not OK)
-> all filekeys for "Tuck & Patti" but including the Media Type Audio! ([Media Type]=[Image] seems to be no limitation)
Code: [Select]
Logfile:
..
0008658: 7436: Sharing Plugins: CHTTPListenerWorker::HandleRequest: TCP: 127.0.0.1: GET: http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck%20&%20Patti]%20[Media%20Type]=[Image]&Action=Serialize&qrOqNbnb
0008658: 7436: Sharing Plugins: JRWebService::Process: Start
0008658: 7436: Sharing Plugins: JRWebService::Process: URL: /MCWS/v1/Files/Search?Query=[Artist]=[Tuck%20&%20Patti]%20[Media%20Type]=[Image]&Action=Serialize&qrOqNbnb
0008658: 7436: Database: CSearchFilesHelper::GetResults: Search: [Artist]=[Tuck; Elapsed ms: 6,772
..

Can anyone give me a hint? What am I doing wrong?

P.S.
I am testing the searches by copy-pasting them into the browser (FireFox 34.0.5). Later I will try this from JavaScript (TrackInfo-template).
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10945
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #1 on: January 04, 2015, 03:50:17 am »

You would need to escape the & when its used inside a field (replace by &), like this:

http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck & Patti] [Media Type]=[Image]&Action=Serialize&qrOqNbnb

Note that spaces are also not valid in URLs, but your browser will convert those automatically for you usually, so you may not see a problem from that immediately.
Logged
~ nevcairiel
~ Author of LAV Filters

winniew

  • World Citizen
  • ***
  • Posts: 102
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #2 on: January 04, 2015, 04:06:11 am »

Hendrik, thank you for your quick answer.
I just tried your change with the escape of &.
But it still gives the wrong result:

http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck & Patti] [Media Type]=[Image]&Action=Serialize&qrOqNbnb
gives me:
2;93;-1;24119834;3152837;3152838;3152839;.. (93 filekeys = not OK, audiofiles are included)

What is wrong with my search phrase?
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10945
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #3 on: January 04, 2015, 04:16:51 am »

Actually my hint was wrong, I was thinking about the wrong escape, you need to replace the & with %26 in URLs, & would be for the response text...

So try this (with spaces also replaced by %20 for good measure):
http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck%20%26%20Patti]%20[Media%20Type]=[Image]&Action=Serialize&qrOqNbnb
Logged
~ nevcairiel
~ Author of LAV Filters

winniew

  • World Citizen
  • ***
  • Posts: 102
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #4 on: January 04, 2015, 04:26:46 am »

That works!

http://localhost:52199/MCWS/v1/Files/Search?Query=[Artist]=[Tuck%20%26%20Patti]%20[Media%20Type]=[Image]&Action=Serialize&qrOqNbnb
now gives me:
2;15;-1;28088469;28088470;28088471;28088472;28088473;28088474;28088476;..  15 filekeys = OK!

Do I have to escape more characters in my search-phrase?

(Ich denke da an die deutschen Umlaute ä ö ü ß Ä Ö Ü und französische accents â à usw.)

Thank you for your quick help!
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10945
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #5 on: January 04, 2015, 04:29:09 am »

If you plan to use it from JavaScript, you should just use a JavaScript URL escape function, that should hopefully deal with it out of the box.
The appropriate JS function to use is probably encodeURIComponent() on each individual parameter before assembling the URL.
Logged
~ nevcairiel
~ Author of LAV Filters

winniew

  • World Citizen
  • ***
  • Posts: 102
Re: Problem with MCWS database search / searchstring containing "&"
« Reply #6 on: January 04, 2015, 04:34:23 am »

If you plan to use it from JavaScript, you should just use a JavaScript URL escape function, that should hopefully deal with it out of the box.
The appropriate JS function to use is probably encodeURIComponent() on each individual parameter before assembling the URL.

I will try that.
Thanks again for your programming lesson!
Logged
Pages: [1]   Go Up