Setting Search Query Properties
Setting The Query properties
Once you have a query defined, perhaps in a form text box, you need
to tell the Query object how to execute it. To create an instance
of the Query object you use the standard Server.CreateObject(ProgID)
thus:
Set objQuery = Server.CreateObject("MSSearch.Query")
This will create an instance of the Query object ready to execute
a search. Before you can start the search you need to specify a few
very important properties:
| Property |
Description |
| Query |
The actual query string, such as 'guru and
tutorial' |
| Columns |
A list of columns to return from the catalog.
For a full list of standard friendly names see ColumnList.
Typically you would include the following columns: DocTitle, DocAddress,
FileWrite, Size, Description, FileName, DocSignature, Rank, HitCount,
DetectedLanguage, MimeType, SiteName, NNTP_MessageID
These will become the columns collection that you can reference
in the resulting ADO RecordSet that is returned from the CreateRecordSet
function.
This is similar to a standard SQL SELECT statement.
|
| MaxRecords |
A slight misnomer: this is NOT the
total number of records that you want to retrieve. It is in
fact the total number of records to fetch per page. This is
useful when you want to show results on a number of pages and allow
the user to navigate back and forth through the pages. This
is used in conjunction with the StartHit and ADO RecordSet NextStartHit
properties. |
| SortBy |
You can specify the order in which columns
are returned. Similar in effect to the SQL ORDER BY
clause. Typically you want the results to be sorted by descending
rank and title, so would use Rank[d],DocTitle |
| Catalog |
Last but not least, you need to tell the
Query object which catalog to use. This is the name that you
entered when you first created your catalog using the Catalog Definition
Wizard.
A generic site search application could set this accordingly. |
So putting this all together in code, your ASP search page would look
something like this:
<%
Const cRecordsPerPage
= 10 '* how many records to show per page
Const cFormCriteriaName = "txtCriteria"
Dim objQuery
'* The
search object
Dim varSearchText
'* The text to search for
Dim objRecordSet
'* Search results set
Set objQuery = Server.CreateObject("MSSearch.Query")
varSearchText = Request.Form(cFormCriteriaName)
objQuery.Query = varSearchText
objQuery.Columns = "DocTitle, DocAddress,
FileWrite, Size, Description,
FileName, DocSignature, Rank, HitCount,
DetectedLanguage, MimeType, SiteName, NNTP_MessageID"
objQuery.MaxRecords = cRecordsPerPage
objQuery.SortBy = "Rank[d],DocTitle"
'* Sort by rank/match then title
%>
Once you've set your query properties you can call the Query
object's CreateRecordSet function to return the list of matching
documents to a standard ADO Recordset object.
You can then display the search results in a table using the standard
ADO Recordset navigation statements, i.e. MoveNext and EOF.
|