Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Possibly to use Query Syntax to match a field starting with a double-quote? (Read 1221 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Possibly to use Query Syntax to match a field starting with a double-quote?

EDIT: I've changed the Subject of this thread to better show the actual issue, since @zeremy showed how my originally described issue could be done in the first reply. Ignore this post and jump to Reply 2 for a better explanation.

I have a song called: Gorgon (7" single B-side)

I would like to be able to find this song using Query Syntax in a query like the following:
TITLE IS "Gorgon (7\" single B-side)"

This doesn't throw an exception (it's a valid Query), but unfortunately the " doesn't seem to be escapable. Replacing it with $char(34) doesn't work. This currently doesn't seem possible to do unless I'm missing something. Note: I'm not trying to find songs with a " in the name (that I can do), I have to do an exact match.

The reason I need this is that in my last.fm playcount component, I'm automatically pulling recent scrobbles and then doing searches on the user's library to determine which tracks might need to have their playcounts updated. This works just fine for everything except songs with a " in the Artist/Album/Title.

Re: Possibly to use Query Syntax to match a field containing a double-quote?

Reply #1
TITLE IS Gorgon (7" single B-side)
gives me a exact match.

Despite the fact that in the Query Syntax Help.html notes:
<field> and <string> in HAS and IS expressions should be enclosed in double quotation marks (”) if they include spaces or parentheses.

??

Re: Possibly to use Query Syntax to match a field containing a double-quote?

Reply #2
TITLE IS Gorgon (7" single B-side)
gives me a exact match.

Despite the fact that in the Query Syntax Help.html notes:
<field> and <string> in HAS and IS expressions should be enclosed in double quotation marks (”) if they include spaces or parentheses.

??
Weird. It works on that song, but it won't work on a song where the first character is a double-quote.

I'm constructing the query syntax in C++, and I don't know what the artist and song title name is going to be so I'm forced to wrap these fields in double-quotes (They could contain $%'(", not to mention they might have the strings AND OR HAS IS ARTIST SORT, etc). The wrapping double-quotes aren't optional for me.

For example, a song that was causing issues for a user was "Адский галоп" (Канкан) из оперетты "Орфей в аду". Which I think translates as Go Ahead and Try to Write a Query Syntax String to Target Me  :)

Re: Possibly to use Query Syntax to match a field starting with a double-quote?

Reply #3
Rather convoluted but seems to work assuming I understood what you wanted:
Code: [Select]
"$if($strstr(%title%,'Gorgon(7'$char(34)' single B-side))'),1,0)" IS 1
So basically do:
Code: [Select]
"$if($strstr(%title%,MYSTRING),1,0)" IS 1
Where MYSTRING is:
1) regular text blocks enclosed between ' '
2) " replaced with $char(34)

Re: Possibly to use Query Syntax to match a field starting with a double-quote?

Reply #4
I think that's basically the solution and was the path I started down, but I took a slightly different approach. $strstr doesn't really suit my needs because of the possibility of a song title containing another song title as a substring, and I'd like to only get exact matches because 99% of the time I'm searching for exactly 1 song in the user's library.

I'm already stripping double-quotes from the titles I get from last.fm to avoid the query bombing out, so i just tried this and it seems to work:
"$replace(%title%,$char(34),)" IS "Gorgon (7 single B-side)"

Also works with songs that start with double-quotes such as: "Cha!" Said the Kitty
"$replace(%title%,$char(34),)" IS "Cha! Said the Kitty"

According to documentation, using titleformatting in query syntax is slow though and I'm doing this 1000x in a loop, so I'll only do this if I know there was a " to replace in the response I got back from last.fm's recentTracks API.

Re: Possibly to use Query Syntax to match a field starting with a double-quote?

Reply #5
You can use $strcmp() or $stricmp() instead of $strstr(). I just started testing with that and forgot to swap it out.

If you are going with your version you could also try replacing " with something really unlikely (e.g '--------') and filter on that accordingly. Not sure if this is actually useful in any way to you, but I'm assuming it would remove a theoretical false match scenario where the only difference between tracks is the " itself.

No idea on the performance hits.

 

Re: Possibly to use Query Syntax to match a field starting with a double-quote?

Reply #6
If you are going with your version you could also try replacing " with something really unlikely (e.g '--------') and filter on that accordingly. Not sure if this is actually useful in any way to you, but I'm assuming it would remove a theoretical false match scenario where the only difference between tracks is the " itself.
Given that my typical query is along the lines of ARTIST IS "..." AND TITLE IS "..." AND ALBUM IS "..." it seems exceedingly rare that I'd need to replace and handle things that way... but I do love to take care of corner cases. I'll probably do something similar.

Though now that I'm thinking about it, I can just replace the double quotes with $char(34) (a pretty unlikely string!) pass that back from my JSON parsing function with a flag to say to use title formatting comparison and then just do "$stricmp(%title%,$char(34)cha!$char(34) said the kitty)" IS 1 like you suggested.

Thanks for the help!