Microsoft Indexing Service and ASP.NET

Querying (contd.)

where parameters

Finally we are able to specify what we want to search for and exclude from the search. In the original example the where predicate was

where FREETEXT(Contents, 'searchText') and
filename <> 'search.aspx'

The rules for searching are as follows

  • Consecutive words are treated as a phrase; they must appear in the same order within a matching document.
  • Queries are case-insensitive, so you can type your query in uppercase or lowercase.
  • You can search for any word except for those in the exception list (for English, this includes a, an, and, as, and other common words), which are ignored during a search. Words in the exception list are treated as placeholders in phrase and proximity queries. For example, if you searched for "Word for Windows", the results could give you "Word for Windows" and "Word and Windows", because for is a noise word and appears in the exception list.
  • Punctuation marks such as the period (.), colon (:), semicolon (;), and comma (,) are ignored during a search. To use specially treated characters such as &, |, ^, #, @, $, (, ), in a query, enclose your query in quotation marks ("). To search for a word or phrase containing quotation marks, enclose the entire phrase in quotation marks and then double the quotation marks around the word or words you want to surround with quotes. For example, "World-Wide Web or ""Web""" searches for World-Wide Web or "Web".
  • You can insert Boolean operators (AND, OR, and NOT) and the proximity operator (NEAR) to specify additional search information.
  • The wildcard character (*) can match words with a given prefix. The query esc* matches the terms "ESC", "escape," and so on.
  • Free-text queries can be specified without regard to query syntax.

where syntax can be a simple comparison such as 'DocAuthor = "Barry Dorrans"', but the real power of the search engine starts to when you use the contains statement.

A simple contains statement might look for a single word or a combination of words in the contents of a document. With near() you can use proximity searching, looking for one word near another, for example contains(' "Visual" near() "Studio" '). Even more useful is formsof() which performs a fuzzy searches. For example contains('formsof(inflectional, "drive") ') examines the root of a word and will match against 'drive', 'driving','driven' or 'drives'. Of course which search method you use depends on the type of search you wish to perform.

The most common method of searching uses the freetext() method. This works much like searching in the Microsoft Office wizards does (without the drawbacks of having that damned paperclip popup). It analyses the meaning of the search criteria in addition to the words it contains and so brings back documents it feels is relevant.

Limiting or exluding documents and directories from the results can be performed using normal SQL syntax, for example filename<>"secretpasswords.htm".

Putting it altogether

So finally we have the search query built and we know how to open the index server catalogue we can simple treat it as a normal OLE command and get a DataReader or a full combination of a DataAdapter and DataSet, with the results being databound to a control if you require.

System.Data.OleDb.OleDbConnection odbSearch =
new System.Data.OleDb.OleDbConnection;
System.Data.OleDb.OleDbCommand cmdSearch
new System.Data.OleDb.OleDbCommand;
odbSearch.ConnectionString =
"Provider=\"MSIDXS\";Data Source=\"idunno.org\";"
cmdSearch.Connection = odbSearch;
cmdSearch.CommandText = "searchSQL"
odbSearch.Open();
OleDbDataReader rdrSearch = cmdSearch.ExecuteReader();
// your databinding or display code here
odbSearch.Close();

After all that you should have a working search facility for your web site.

Indexing .aspx and .ascx files

By default the Indexing Service does not index .aspx and .ascx files. If you want to extend the file types indexed to include your asp.net content follow the instructions in the Microsoft Knowledge Base article 311521.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens