Thank you so much for writing this post; saved me from quite a headache just now!

I just performed a fresh install of OS X to a new hard disk and the Mac App Store application claimed I had already installed Xcode. It turns out the Applications directory on my old drive was getting indexed (or something to that effect). The command you posted solved my problem until I once again viewed my old hard drive's Applications folder using Finder.

That said, I believe I will need to disconnect the old hard drive for the App Store to continue to behave sanely. Blacklisting the old drive in Spotlight's preferences did not work.