You are here: com.dtsearch.engine Package > Interfaces > DataSource Interface
dtSearch Engine API for Java
DataSource Interface

Interface for the dataSourceToIndex member of IndexJob, for indexing non-file data sources such as databases.


Package: com.dtsearch.engine 

public interface DataSource;

An IndexJob 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. The text may exist as rows in a remote SQL database or in a message store. 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 using setDataSourceToIndex. 

A data source is an object that implements the methods in the DataSource, DataSource2, or DataSource3 interfaces.


The dtSearch Engine will call the getNextDoc method of your DataSource implementation to obtain documents to index. On each call, dtSearch will use the properties supplied (getDocName, getDocModifiedDate, getDocFields) to set up a document object to index. To index binary document data, use setDocBytes in the DataSource2 interface or setDocStream in the DataSource3 interface.

Field Names

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:

*SampleField<TAB>Some Text

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. 

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. 

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.

Related articles

Database and Field Searching

Copyright (c) 1998-2021 dtSearch Corp. All rights reserved.