How to index data from COM object interfaces such as ADO, CDO, etc.
An IndexJob (IIndexJob) provides two ways specify the text you want to index: by files (the toAdd* properties) and by data source (the DataSourceToIndex property). Most commonly, the text exists in disk files, in which case you would specify the files to be indexed using folder names and include and exclude filters. In some situations, however, the text to be indexed may not be readily available as disk files. For example, the text may exist as rows in a remote SQL database or in Microsoft Exchange message stores. You could copy the text from the database to local disk files and index the local disk files, but the dtSearch Engine provides a more direct and efficient solution. To supply this text to the dtSearch indexing engine, you create an object that accesses the text and then attach the object to an IndexJob as the DataSourceToIndex property.
The DataSourceToIndex property is a Visual Basic object (or other IDispatch object), that implements the following methods and properties:
Method |
Purpose |
Rewind |
Initialize the data source so that the next GetNextDoc call will return the first document. Rewind returns 0 if it succeds, non-zero if the data source is empty. |
GetNextDoc |
Get the next document from the data source. The document information is stored in the properties. GetNextDoc returns 0 if it succeeds, non-zero if there are no more documents. |
Property |
Purpose |
DocName |
The DocName is the name of the document, as you want it to appear in search results. This can be any legal Win32 filename. |
DocIsFile |
If True, DocName will be interpreted as the name of a file to be indexed, and dtSearch will index the contents of the file along with any data provided in DocText and DocFields. The DocModifiedDate will still be used as the modification date of the document. |
DocDisplayName |
The DocDisplayName is a user-friendly version of the filename, which the dtSearch end-user product displays in search results. If blank, the DocName will be used. |
DocModifiedDate |
The date that the document was last modified. |
DocText |
In DocText, supply the text you want the dtSearch Engine to index. This must be plain text that dtSearch can index directly. If you need to index text that is in a document, you can use a FileConverter to convert the document data to plain text. |
DocFields |
In DocFields, supply any fielded data you want the dtSearch Engine to index. DocFields consists of a series of pairs of field names and values, with tab characters (chr$(9)) between them. |
DocId,DocWordCount, DocTypeId |
Properties that indicate how the previously-returned document was indexed (see "Returned Properties" below) |
After a search that retrieves a document that was returned from the DataSourceToIndex object, you can generate a hit-highlighted version of the document using FileConverter's InputText, InputFields, and InputFile properties.
To do this, set up the FileConverter with the same data supplied by your data source. Set the FileConverter's InputFields property to the value of DocFields, the InputText property to the value of DocText, and, if DocIsFile was set to true, set the InputFile property to the value of DocName. For sample code, see the dsdemo Visual Basic sample.
By default, field names are searchable along with field text. For example, if DocFields contains SampleField<TAB>Some Text, then you can find the document in a search either for "SampleField contains Text" or just "SampleField". To prevent a field name from being searchable, add * (asterisk) in front, like this:
When a field name begins with *, only the text of the field is searchable, but not the name. Therefore, you can find the document in a search for "SampleField contains Text" but not by searching for just "SampleField". The * is not considered part of the field name for purposes of searching or designating stored fields. For sample code demonstrating non-searchable field names, see the dsdemo Visual Basic sample.
When a field name begins with **, the field is considered a "hidden stored" field. The contents of a hidden stored field are not searchable at all, and are automatically stored in the index as document properties when the document is indexed. To retrieve the value of a hidden stored field after a search, use SearchResults.DocDetailItem("FieldName").
Field names can include nesting. Example: Meta/Subject<TAB> This is the subject<TAB>Meta/Author<TAB> This is the author
In this example, you could search across both fields by searching for "Meta contains (something)", or you could search for "Author contains (something)", or you could search for "Meta/Author contains (something)" to distinguish this Author field from any other Author fields that might be present in the document. For more information on searching for nested fields, see: Field Searching
Each time GetNextDoc is called, the following properties will provide status information about how the previously-returned document was indexed:
For sample code demonstrating the use of returned properties, see the dsdemo sample application.
This example demonstrates indexing of a database table using Microsoft Active Data Objects. The example assumes that the RecordSet will be created using a SELECT statement, which is not shown.