Skip to content
Advertisement

Exception when SQL query has multiple word string to W10 desktop search index

I’ve gobbled together a basic Powershell script to query W10’s Windows Desktop Search (WDS) index. Here is the relevant bits,

Until now my tests have been using single words and everything works. But when I started using two words, it falls apart with the following error,

Using Explorer to query the index using content:"and then" works fine.

Any ideas?

Advertisement

Answer

According to the documentation for Windows Search SQL Syntax and the examples in the CONTAINS predicate, if you want to search for a literal phrase with “multiple words or included spaces” you need to quote the phrase inside the query:

Type: Phrase

Description: Multiple words or included spaces.

Examples

...WHERE CONTAINS('"computer software"')

So in your example you probably want:

(note the quotes are prefixed with a backtick as the quote would otherwise terminate your entire query string.)

If you’re not looking for the exact phrase “and then”, and you just want results that contain “and” and “then” it looks like you need to to do something like this:

Type: Boolean

Description: Words, phrases, and wildcard strings combined by using the Boolean operators AND, OR, or NOT. Enclose the Boolean terms in double quotation marks.

Example:

...WHERE CONTAINS('"computer monitor" AND "software program" AND "install component"')

...WHERE CONTAINS(' "computer" AND "software" AND "install" ' )

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement