com.groupdocs.search

Class IndexRepository

  • All Implemented Interfaces:
    Closeable, AutoCloseable


    public class IndexRepository
    extends Object
    implements Closeable

    Represents a container for combining multiple indexes and performing common operations on them.

    The example demonstrates a typical usage of the class.

     String indexFolder1 = "c:\\MyIndex\\";
     String indexFolder2 = "c:\\MyIndex\\";
     String query = "Einstein";
     IndexRepository repository = new IndexRepository();
     repository.addToRepository(indexFolder1); // Loading an existing index
     repository.addToRepository(indexFolder2); // Loading another existing index
     SearchResult result = repository.search(query); // Searching in indexes of the repository
     
    • Constructor Detail

      • IndexRepository

        public IndexRepository()

        Initializes a new instance of the IndexRepository class.

    • Method Detail

      • finalize

        protected void finalize()
                         throws Throwable

        Finalizes an instance of the IndexRepository class.

        Overrides:
        finalize in class Object
        Throws:
        Throwable
      • getEvents

        public final EventHub getEvents()

        Gets the event hub for subscribing to events.

        Returns:
        The event hub for subscribing to events.
      • getIndexes

        public final Index[] getIndexes()

        Gets the indexes contained in this IndexRepository.

        Returns:
        The indexes.
      • close

        public final void close()

        Releases all resources used by the IndexRepository.

        Specified by:
        close in interface Closeable
        Specified by:
        close in interface AutoCloseable
      • create

        public final Index create()

        Creates a new index in memory.

        Returns:
        The created index.

        The example demonstrates how to create an index in memory through the index repository.

         IndexRepository indexRepository = new IndexRepository();
         Index index = indexRepository.create();
         
      • create

        public final Index create(IndexSettings settings)

        Creates a new index in memory.

        Parameters:
        settings - The index settings.

        The example demonstrates how to create an index in memory through the index repository.

         IndexRepository indexRepository = new IndexRepository();
         IndexSettings settings = new IndexSettings();
         settings.setUseStopWords(false); // Disabling use of stop words during indexing
         Index index = indexRepository.create(settings);
         
        Returns:
        The created index.
      • create

        public final Index create(String indexFolder)

        Creates a new index on disk. The index folder will be cleaned before the index creation.

        Parameters:
        indexFolder - The index folder.

        The example demonstrates how to create an index on disk through the index repository.

         String indexFolder = "c:\\MyIndex\\";
         IndexRepository indexRepository = new IndexRepository();
         Index index = indexRepository.create(indexFolder);
         
        Returns:
        The created index.
      • create

        public final Index create(String indexFolder,
                   IndexSettings settings)

        Creates a new index on disk. The index folder will be cleaned before the index creation.

        Parameters:
        indexFolder - The index folder.
        settings - The index settings.

        The example demonstrates how to create an index on disk through the index repository.

         String indexFolder = "c:\\MyIndex\\";
         IndexRepository indexRepository = new IndexRepository();
         IndexSettings settings = new IndexSettings();
         settings.setUseStopWords(false); // Disabling use of stop words during indexing
         Index index = indexRepository.create(indexFolder, settings);
         
        Returns:
        The created index.
      • addToRepository

        public final void addToRepository(Index index)

        Adds an index to the index repository.

        Parameters:
        index - The index to add.

        The example demonstrates how to add an index to the index repository.

         Index index = new Index();
         IndexRepository indexRepository = new IndexRepository();
         indexRepository.addToRepository(index);
         
      • addToRepository

        public final void addToRepository(String indexFolder)

        Opens and adds an index to the index repository.

        Parameters:
        indexFolder - The index folder.

        The example demonstrates how to add an index to the index repository.

         String indexFolder = "c:\\MyIndex\\";
         IndexRepository indexRepository = new IndexRepository();
         indexRepository.addToRepository(indexFolder);
         
      • update

        public final void update()

        Updates all indexes in the repository.

        The example demonstrates how to update indexes in the repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         // Delete documents from the documents folder or modify them or add new documents to the folder
         repository.update();
         
      • update

        public final void update(UpdateOptions options)

        Updates all indexes in the repository.

        Parameters:
        options - The update options.

        The example demonstrates how to update indexes in the repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         // Delete documents from the documents folder or modify them or add new documents to the folder
         UpdateOptions options = new UpdateOptions();
         options.setThreads(2); // Setting the number of indexing threads
         repository.update(options);
         
      • search

        public final SearchResult search(String query)

        Searches in all indexes of the repository.

        Parameters:
        query - The search query.

        The example demonstrates how to perform search in index repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         String query = "Einstein";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         SearchResult result = repository.search(query); // Searching
         
        Returns:
        The search result.
      • search

        public final SearchResult search(String query,
                          SearchOptions options)

        Searches in all indexes of the repository.

        Parameters:
        query - The search query.
        options - The search options.

        The example demonstrates how to perform search in index repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         String query = "Einstein";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         SearchOptions options = new SearchOptions();
         options.setUseCaseSensitiveSearch(true); // Setting flag of case sensitive search
         SearchResult result = repository.search(query, options); // Searching
         
        Returns:
        The search result.
      • search

        public final SearchResult search(SearchQuery query)

        Searches in all indexes of the repository.

        Parameters:
        query - The search query.

        The example demonstrates how to perform search in index repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         SearchQuery query = SearchQuery.createWordQuery("Einstein"); // Creating search query in object form
         SearchResult result = repository.search(query); // Searching
         
        Returns:
        The search result.
      • search

        public final SearchResult search(SearchQuery query,
                          SearchOptions options)

        Searches in all indexes of the repository.

        Parameters:
        query - The search query.
        options - The search options.

        The example demonstrates how to perform search in index repository.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         IndexRepository repository = new IndexRepository();
         Index index = repository.create(indexFolder); // Creating index
         index.add(documentsFolder); // Indexing documents
         SearchOptions options = new SearchOptions();
         options.setUseCaseSensitiveSearch(true); // Setting flag of case sensitive search
         SearchQuery query = SearchQuery.createWordQuery("Einstein"); // Creating search query in object form
         SearchResult result = repository.search(query, options); // Searching
         
        Returns:
        The search result.