Reputation: 4492
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:
FREETEXT('ab')
FREETEXT('*ab*')
FREETEXT('\"ab\"')
FREETEXT('\"*ab*\"')
FREETEXT('*\"ab\"*')
FREETEXT('ab*')
FREETEXT('\"*ab*\"')
FREETEXT('\"ab\"*')
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
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
Reputation: 15281
There's a COP_VALUE_CONTAINS operator. The SQL symbol is ~= or ~~. E.g. System.FullText :~="abc".
Upvotes: 0
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