You can keep control of the progress of the index using IsThreadDone, AbortThread and so on. Instead of calling Execute, all you have to do is call ExecuteInThread and the call returns immediately and the indexing proceeds on another thread. In this case dtSearch makes this very easy for you. The standard solution in this case is to run the long blocking process on another thread. In most cases the construction of an index takes more time that you can afford to have the UI blocked for. The complete program is: IndexJob indexJob = new = name\Įxecute may be simple but it isn't really of much use.ĭo you really want your indexing program to wait unresponsively while the index is constructed? So, to complete the program, we have to add: bool result = indexJob.Execute() This starts the indexing off and only returns with a Boolean to indicate success or failure when the index is complete. The simplest way to do this is to use the Execute method. The IndexJob is now setup with minimal configuration and we can start it going. To create a new empty index and add files to it you have to set both: indexJob.ActionCreate = true The ActionAdd property allows new documents to be added to the index. If the index already exists then it is overwritten. The ActionCreate property has to be set to true for the indexing operation to create a new index. For simplicity we will ignore filters.įinally, we have to set some "Action" properties that indicate how the indexing operation should be performed. You can also add include and exclude filters to specify which types of file are to be indexed. If you don't add then just the content of the specified folder is indexed. For the example we will add just one: can add a to the end of the path to signify that all of the subfolders should be indexed. You can add as many strings specifying paths to folders to this collection as you need. This is achieved using the FoldersToIndex string collection. Next you have to specify the folders and file that you would like to index. Notice that you specify the directory that the files for the index are created in. So what do you have to specify to create an index?įirst you have to say where you want the index to be created: indexJob.IndexPath = is no particular reason to use this location it is just the default used by the dtSearch Desktop utility for the indexes it creates.
You simply set the properties of the IndexJob object to specify the index you want to create and call one of the Execute methods to build or update the index. All you need is an IndexJob object: IndexJob indexJob = new IndexJob() Start a new C# project and make sure you have added a reference to the dtSearch library and have added: using dtSearch.Engine Ĭreating an index under program control with dtSearch is exceptionally simple. If not read Getting started with dtSearch.
It is also assumed that you already know how to create an index and search it using say C#.
So let's first look at how to create a standard index in code and then extend this to using a more general data source.įirst you will need a copy of dtSearch and to follow this example it is suggested you download the 30-day evaluation from. You do however want to write code to create an index if the data source is something other than files stored in folder. In fact there is usually very little reason to write programs to create an index - but it can be done and it isn't difficult. This is something that dtSearch can do automatically using the desktop utility.
Most of the time you want to create a full text index of a set of files stored in a collection of directories. The first thing we need to learn is how to create an index under program control. In this article we take a look at how you can index documents of all kinds stored in container you care to think up - and not just a database. It can index documents stored in a database or anywhere for that matter. If you want to create a full text search facility you have to index the database. This is fine for a lot of retrieval situations but what if you want to perform complex searches on the contents of the documents? For example, in the case of a data-based website the articles are stored in a database. Much of the time the documents that you want to index are stored in a collection of folders but increasingly databases are used to store documents of all types complete with a simple keyword or metadata index. The answer is yes, but by comparison with the sort of thing dtSearch is designed to do they are very simple indexes.
You might think that the idea of bringing in a separate piece of software to index a database is slightly crazy - after all aren't databases supposed to be all about indexes? Continuing our look at how dtSearch makes full text indexing and search easy, we now move on to consider the strange topic of indexing databases.