slayernoah
slayernoah

Reputation: 4492

Windows search query for a *part* of a word/substring in file contents

I am trying to query the Windows Search index programmatically using the Windows Search SQL Syntax

I am able to search file contents in my C# winforms application using the search query below:

string strSearchQuery =
    "SELECT System.ItemName FROM SystemIndex " +
    "WHERE scope ='file:" + @"C:\myfolder\" + 
    "' and FREETEXT('dummy')";

ISSUE: However, I am not able to use this query to search for part of a word in the file contents.

For example: If a file (such as a .txt file) contains the the text "abcd", and I search for FREETEXT('ab'), it doesn't show that file.

I have tried using:

I've also tried using CONTAINS with the above combinations instead of FREETEXT.

When I search for ab directly on Windows search, it shows the file having the text

How can I modify this query to search for a part of a word in the file contents? Please help!

Upvotes: 3

Views: 1876

Answers (3)

Victor David
Victor David

Reputation: 31

FREETEXT() does not support wild cards. Use CONTAINS() instead.

string query = 
   "SELECT System.ItemName, System.ItemUrl FROM SystemIndex " +
   "WHERE scope ='file:D:\MyFolder' and CONTAINS('\"dumm*\"')";

Note that the partial word you want to search on must be contained within double quotes, along with the wildcard * character.

Upvotes: 3

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15281

There's a COP_VALUE_CONTAINS operator. The SQL symbol is ~= or ~~. E.g. System.FullText :~="abc".

Upvotes: 0

Shachaf.Gortler
Shachaf.Gortler

Reputation: 5745

The wildcard character is the %, so your query should look like this :

string strSearchQuery =
    "SELECT System.ItemName FROM SystemIndex " +
    "WHERE scope ='file:" + @"C:\myfolder\" + 
    "' and FREETEXT(%'dummy'%)";

EDIT :

 string strSearchQuery =
        "SELECT System.ItemName FROM SystemIndex " +
        "WHERE scope ='file:" + @"C:\myfolder\" + 
        "' and FREETEXT('%dummy%')";

Upvotes: 0

Related Questions