IndexRepository
Inheritance: java.lang.Object
All Implemented Interfaces: java.io.Closeable
public class IndexRepository implements Closeable
Represents a container for combining multiple indexes and performing common operations on them.
Learn more
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
```
Constructors
| Constructor | Description |
|---|---|
| IndexRepository() | Initializes a new instance of the |
| IndexRepository | |
| class. | |
Methods
| Method | Description |
|---|---|
| getEvents() | Gets the event hub for subscribing to events. |
| getIndexes() | Gets the indexes contained in this |
| IndexRepository | |
| . | |
| close() | Releases all resources used by the |
| IndexRepository | |
| . | |
| create() | Creates a new index in memory. |
| create(IndexSettings settings) | Creates a new index in memory. |
| create(String indexFolder) | Creates a new index on disk. |
| create(String indexFolder, IndexSettings settings) | Creates a new index on disk. |
| addToRepository(Index index) | Adds an index to the index repository. |
| addToRepository(String indexFolder) | Opens and adds an index to the index repository. |
| update() | Updates all indexes in the repository. |
| update(UpdateOptions options) | Updates all indexes in the repository. |
| search(String query) | Searches in all indexes of the repository. |
| search(String query, SearchOptions options) | Searches in all indexes of the repository. |
| search(SearchQuery query) | Searches in all indexes of the repository. |
| search(SearchQuery query, SearchOptions options) | Searches in all indexes of the repository. |
IndexRepository()
public IndexRepository()
Initializes a new instance of the IndexRepository class.
getEvents()
public final EventHub getEvents()
Gets the event hub for subscribing to events.
Returns: EventHub - The event hub for subscribing to events.
getIndexes()
public final Index[] getIndexes()
Gets the indexes contained in this IndexRepository .
Returns: com.groupdocs.search.Index[] - The indexes.
close()
public final void close()
Releases all resources used by the IndexRepository .
create()
public final Index create()
Creates a new index in memory.
Returns: Index - 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(IndexSettings settings)
public final Index create(IndexSettings settings)
Creates a new index in memory.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| settings | IndexSettings | 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: Index - The created index.
create(String indexFolder)
public final Index create(String indexFolder)
Creates a new index on disk. The index folder will be cleaned before the index creation.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| indexFolder | java.lang.String | 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: Index - The created index.
create(String indexFolder, IndexSettings settings)
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:
| Parameter | Type | Description |
|---|---|---|
| indexFolder | java.lang.String | The index folder. |
| settings | IndexSettings | 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: Index - The created index.
addToRepository(Index index)
public final void addToRepository(Index index)
Adds an index to the index repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| index | 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(String indexFolder)
public final void addToRepository(String indexFolder)
Opens and adds an index to the index repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| indexFolder | java.lang.String | 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(UpdateOptions options)
public final void update(UpdateOptions options)
Updates all indexes in the repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| options | UpdateOptions | 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(String query)
public final SearchResult search(String query)
Searches in all indexes of the repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| query | java.lang.String | 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: SearchResult - The search result.
search(String query, SearchOptions options)
public final SearchResult search(String query, SearchOptions options)
Searches in all indexes of the repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| query | java.lang.String | The search query. |
| options | SearchOptions | 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: SearchResult - The search result.
search(SearchQuery query)
public final SearchResult search(SearchQuery query)
Searches in all indexes of the repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| query | SearchQuery | 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: SearchResult - The search result.
search(SearchQuery query, SearchOptions options)
public final SearchResult search(SearchQuery query, SearchOptions options)
Searches in all indexes of the repository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| query | SearchQuery | The search query. |
| options | SearchOptions | 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: SearchResult - The search result.