Windows Search (WDS 4)
Written by Mike James   
Monday, 22 February 2010
Article Index
Windows Search (WDS 4)
Getting Started
Making the connection
Binding to a grid
Binding in WPF
More properties
Scope and content

 

It is worth knowing that you can control where a search occurs in a much more efficient manner than simply writing a condition on System.ItemPathDisplay which would simply search everywhere but only return documents that had a path that matched the specification.

If you use the SCOPE or the DIRECTORY predicates you can control where the search is performed. The difference between the two is that SCOPE does a deep search, i.e. including all subfolders, but DIRECTORY does a shallow search, i.e. just the folder you specify. For example:

 @"WHERE SCOPE='file:C:\Files\Reports'"

searches C:/Files/Reports and all the subfolders it contains whereas:

 @"WHERE DIRECTORY=
'file:C:\Files\Reports'"

searches just C:\Files\Reports.

Notice that SCOPE and DIRECTORY don't work as described in the documentation. There is no need to put "//" after "file:" and you can use either "/" or "\" in the path specification.

Content

The real power of the search engine is that it indexes the contents of a wide range of files. If you want to search the contents of indexed files you need to know about FREETEXT and CONTAINS. FREETEXT is the simpler of the two and it enables you to search for a fixed phrase. For example:

 WHERE FREETEXT('iProgrammer')

searches for any file that contains "iProgrammer".

You can also add a column specification so that properties are searched along with content. For example to search all of the properties and content use:

 WHERE FREETEXT(All,'iProgrammer')

FREETEXT uses a variety of matching algorithms and will return a measure of how well the document matches the search criteria in System.Search.Rank which you can retrieve and use. You can modify the way the rank is calculated using the RANK BY clause – see the documentation for more information.

The CONTAINS predicate is more suited to looking for exact matches. You can specify what you are looking for using AND, OR and NOT and use wildcards. For example, to find any word starting with "iProg" you would use:

 WHERE CONTAINS('iProg*')

You can also use NEAR to find occurrences of one word near another, FORMSOF to match for words and inflections of the word. For example to find documents containing run, ran or running you would use:

 CONTAINS('FORMSOF(INFLECTIONAL,run)')

Full text searches are clearly powerful but a programmed search can generally do more by including conditions on properties such as System.Author or System.DateCreated.

More Searching?

The Desktop Search facility is very powerful and we have only just scratched the surface but we have looked at a little of almost every aspect of its operation and proved that databases are easy. You should now find it possible to follow the documentation provided on the Microsoft website and create custom search applications that do exactly what you need.

To access the code for this project, once you have registered, click on CodeBin.

<ASIN:0615204252>

<ASIN:0735625352>

<ASIN:0596800959>

<ASIN:1430225491>

but if you are using Windows Vista, XP or Windows 2003/8 then you will have to download and install it.


Last Updated ( Sunday, 21 February 2010 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.