Hi,
I admit, that haven't really understand, what Your Query shall do, but there are 2 Ideas I had:
1. If there is an empty Topic, you compare with an empty value. I guess You should use a Wildcard or leave this check away.
2. If the field comment is empty Your Query will End with the >AND< Operator of the last expression. I suggest to change all the Strings from Ending AND to Leading AND of the Expression before.
I hope this will help a little.
dibap