The IndexRepository class can be used to combine several indexes into a group for searching all indexes at once. In addition, a single call to the Update method can update all indexes in the repository. And also the index repository serves as an event hub for all indexes in it. That is, you can subscribe to any events available for the index also through the index repository. However, note that indexing documents is performed separately for each index.
To start using the index repository, indexes must be created or loaded and added to an instance of the index repository. Examples of creating and adding indexes to the repository are presented below.
C#
stringindexFolder1=@"c:\MyIndex1\";stringindexFolder2=@"c:\MyIndex2\";stringdocumentsFolder1=@"c:\MyDocuments1\";stringdocumentsFolder2=@"c:\MyDocuments2\";// Creating an index repository instanceIndexRepositoryindexRepository=newIndexRepository();// Creating or loading an index and adding to the index repositoryIndexindex1=newIndex(indexFolder1);indexRepository.AddToRepository(index1);// Creating an index via the index repository by calling a single methodIndexindex2=indexRepository.Create(indexFolder2);// Adding documents to the index 1index1.Add(documentsFolder1);// Adding documents to the index 2index2.Add(documentsFolder2);
The following example shows how to subscribe to the repository events, update indexes in the repository, and search in the repository.
C#
stringindexFolder1=@"c:\MyIndex1\";stringindexFolder2=@"c:\MyIndex2\";stringdocumentFolder1=@"c:\MyDocuments1\";stringdocumentFolder2=@"c:\MyDocuments2\";// Creating an index repository instanceIndexRepositoryindexRepository=newIndexRepository();// Subscribing to an eventindexRepository.Events.ErrorOccurred+=(sender,args)=>{Console.WriteLine("Index: "+args.IndexFolder);Console.WriteLine("Error: "+args.Message);};// Creating or loading an index and adding to the index repositoryIndexindex1=newIndex(indexFolder1);indexRepository.AddToRepository(index1);// Creating or loading an index and adding to the index repositoryIndexindex2=newIndex(indexFolder2);indexRepository.AddToRepository(index2);// Adding documents to the index 1index1.Add(documentFolder1);// Adding documents to the index 2index2.Add(documentFolder2);// Changing, deleting, adding documents to document folders// ...// Updating all indexes in the repositoryindexRepository.Update();// Searching in the repositorySearchResultresult=indexRepository.Search("Einstein");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: